Hi, I'm trying to figure out how to do this contains method. everything that's in the method is my code. My thinking is: start at root and go in Inorder traversal and use .equals(). Should I even do that? is there a way I can compare the data, since BST will have lower value to left and higher in right child? I'm lost.
/** Searches for a given element in the binary search tree @param someElement element to be searched @return true - if someElement is found in the tree; false otherwise */ // Complexity: O(h) - where h is the height of the tree. In the worst case it could be O(n). But on average // we can expect a complexity of O(log n) public boolean contains( E someElement) { Node node1 = root; if(root == someElement) return true; if(node1.left != null){ boolean result = someElement.equals(node1.left); if(result == false){ contains((E) node1); } } }