Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //find method
  2. public T find (T Element) {
  3. if (isEmpty())
  4. throw new EmptyCollectionException();
  5. BinaryTreeNode<T> current = getNode((Comparable<T>)Element,root);
  6.  
  7. if(current==null){
  8. throw new ElementNotFoundException();
  9.  
  10. return(current.element);
  11. }
  12.  
  13. //contains method
  14.  
  15. public boolean contains(T Element){
  16.  
  17. BinaryTreeNode<T> current = getNode((Comparable<T>)targetElement, root);
  18.  
  19. if (current == null)
  20. return false;
  21. else
  22. return true;
  23. }
  24.  
  25. //getNode Method
  26.  
  27. private BinaryTreeNode<T> getNode(Comparable<T>Element,BinaryTreeNode<T>,next){
  28. BinaryTreeNode<T> current = next;
  29.  
  30. if(current == null)
  31. return null;
  32.  
  33. else if(Element.compareTo(current.element)==0)
  34. return current;
  35.  
  36. else if(Element.compareTo(current.element)<0)
  37. current = getNode(Element,current.left);
  38.  
  39. else
  40. current = getNode(Element,current.right);
  41.  
  42. return current;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement