Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. public boolean contains(T targetElement) {
  2.         BinaryTreeNode<T> tempNode = root;
  3.         boolean found = false;
  4.         while (!found) {
  5.             T tempValue = tempNode.getElement();
  6.             if (targetElement.equals(tempValue)) {
  7.                 return true;
  8.             } else if (tempValue.equals(null)) {
  9.                 return false;
  10.             } else if (((Comparable<T>) targetElement).compareTo(tempValue) < 1) {
  11.                 tempNode = tempNode.getRight();
  12.             } else {
  13.                 tempNode = tempNode.getLeft();
  14.             }
  15.         }
  16.         return false;
  17.  
  18.     }
  19.  
  20.     public T find(T targetElement) throws ElementNotFoundException {
  21.         BinaryTreeNode<T> tempNode = root;
  22.         boolean found = false;
  23.         while (!found) {
  24.             T tempValue = tempNode.getElement();
  25.             if (targetElement.equals(tempValue)) {
  26.                 return tempValue;
  27.             } else if (tempValue.equals(null)) {
  28.                 return null;
  29.             } else if (((Comparable<T>) targetElement).compareTo(tempValue) < 1) {
  30.                 tempNode = tempNode.getRight();
  31.             } else {
  32.                 tempNode = tempNode.getLeft();
  33.             }
  34.         }
  35.         return null;
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement