Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node current = root;
- boolean found = false;
- if(current.getKeyOne().compareTo(x) == 0 || current.getKeyTwo().compareTo(x) == 0) {
- found = true;
- }
- if(current.getKeyOne().compareTo(x) > 0) {
- while(current.left != null && found != true) {
- current = current.left;
- if(current.getKeyOne().compareTo(x) == 0 || current.getKeyTwo().compareTo(x) == 0) {
- found = true;
- }
- }
- }
- if(current.getKeyTwo().compareTo(x) < 0) {
- while(current.right != null && found != true) {
- current = current.right;
- if(current.getKeyOne().compareTo(x) == 0 || current.getKeyTwo().compareTo(x) == 0) {
- found = true;
- }
- }
- }
- if(current.getKeyTwo() != null) {
- return String.valueOf(current.getKeyOne()) + " " + String.valueOf(current.getKeyTwo());
- }
- else {
- return String.valueOf(current.getKeyOne());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement