Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public boolean containsKey(E value){
  2. BinaryTree<E> temp = this;
  3. boolean have = false;
  4. int compare;
  5. while(!have)
  6. {
  7. compare = value.compareTo(temp.getValue());
  8. if (compare < 0)
  9. {
  10. temp = temp.getLeft();
  11. if(temp.isEmpty())
  12. return false;
  13. if (temp.getValue().equals(value))
  14. have = true;
  15. }
  16. else
  17. if (compare > 0)
  18. {
  19. temp = temp.getRight();
  20. if (temp.isEmpty())
  21. return false;
  22. if (temp.getValue().equals(value))
  23. have = true;
  24. }
  25. }
  26. return true;
  27.  
  28.  
  29. /*int cmp = value.compareTo(this.value);
  30. if(cmp > 0)
  31. return right.containsKey(value);
  32. if(cmp < 0)
  33. return left.containsKey(value);
  34. return true;
  35. */
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement