Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Node current = root;
  2. boolean found = false;
  3. if(current.getKeyOne().compareTo(x) == 0 || current.getKeyTwo().compareTo(x) == 0) {
  4. found = true;
  5. }
  6. if(current.getKeyOne().compareTo(x) > 0) {
  7. while(current.left != null && found != true) {
  8. current = current.left;
  9. if(current.getKeyOne().compareTo(x) == 0 || current.getKeyTwo().compareTo(x) == 0) {
  10. found = true;
  11. }
  12. }
  13. }
  14. if(current.getKeyTwo().compareTo(x) < 0) {
  15. while(current.right != null && found != true) {
  16. current = current.right;
  17. if(current.getKeyOne().compareTo(x) == 0 || current.getKeyTwo().compareTo(x) == 0) {
  18. found = true;
  19. }
  20. }
  21. }
  22. if(current.getKeyTwo() != null) {
  23. return String.valueOf(current.getKeyOne()) + " " + String.valueOf(current.getKeyTwo());
  24. }
  25. else {
  26. return String.valueOf(current.getKeyOne());
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement