Last active
December 11, 2015 20:48
-
-
Save gtke/4657491 to your computer and use it in GitHub Desktop.
BST Searching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public boolean search(T data, Node<T> node){ | |
| if(data != null){ | |
| if(data.compareTo(node.getData()) == 0){ | |
| return true; | |
| }else{ | |
| if(data.compareTo(node.getData()) < 0){ | |
| if(node.left == null){ | |
| return false; | |
| }else{ | |
| return search(data, node.left); | |
| } | |
| }else if(data.compareTo(node.getData()) > 0){ | |
| if(node.right == null){ | |
| return false; | |
| }else{ | |
| return search(data, node.right); | |
| } | |
| } | |
| } | |
| } | |
| else{ | |
| Node<T> max = root; | |
| while(max != null){ | |
| if(max.getData()==null){ | |
| return true; | |
| } | |
| max = max.right; | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment