Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean contains(T targetElement) {
- BinaryTreeNode<T> tempNode = root;
- boolean found = false;
- while (!found) {
- T tempValue = tempNode.getElement();
- if (targetElement.equals(tempValue)) {
- return true;
- } else if (tempValue.equals(null)) {
- return false;
- } else if (((Comparable<T>) targetElement).compareTo(tempValue) < 1) {
- tempNode = tempNode.getRight();
- } else {
- tempNode = tempNode.getLeft();
- }
- }
- return false;
- }
- public T find(T targetElement) throws ElementNotFoundException {
- BinaryTreeNode<T> tempNode = root;
- boolean found = false;
- while (!found) {
- T tempValue = tempNode.getElement();
- if (targetElement.equals(tempValue)) {
- return tempValue;
- } else if (tempValue.equals(null)) {
- return null;
- } else if (((Comparable<T>) targetElement).compareTo(tempValue) < 1) {
- tempNode = tempNode.getRight();
- } else {
- tempNode = tempNode.getLeft();
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement