Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean containsKey(E value){
- BinaryTree<E> temp = this;
- boolean have = false;
- int compare;
- while(!have)
- {
- compare = value.compareTo(temp.getValue());
- if (compare < 0)
- {
- temp = temp.getLeft();
- if(temp.isEmpty())
- return false;
- if (temp.getValue().equals(value))
- have = true;
- }
- else
- if (compare > 0)
- {
- temp = temp.getRight();
- if (temp.isEmpty())
- return false;
- if (temp.getValue().equals(value))
- have = true;
- }
- }
- return true;
- /*int cmp = value.compareTo(this.value);
- if(cmp > 0)
- return right.containsKey(value);
- if(cmp < 0)
- return left.containsKey(value);
- return true;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement