Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public boolean removeHelp(Key key, Top top, Top parent, Boolean links) {
  2. if (lookup(key)) {
  3. if (key.compareTo(top.getKey()) == Key.LT) {
  4. removeHelp(key, top.getLeft(), top,true);
  5. } else if (key.compareTo(top.getKey()) == Key.GT) {
  6. removeHelp(key, top.getRight(), top, false);
  7. } else {
  8. if (top.hasLeft() && top.hasRight()) {
  9. Top maxFromLeft = max(top.getLeft());
  10. top = maxFromLeft;
  11. removeHelp(maxFromLeft.getKey(), top.getLeft(), top, true);
  12.  
  13. } else if (top.hasLeft()) {
  14. top.setKey(top.getLeft().getKey());
  15. removeHelp(top.getLeft().getKey(), top, top, true);
  16. } else if (top.hasRight()) {
  17. top.setKey(top.getRight().getKey());
  18. removeHelp(top.getRight().getKey(), top, top, false);
  19. } else {
  20. if (links) {
  21. parent.setLeft(null);
  22. } else {
  23. parent.setRight(null);
  24. }
  25. return true;
  26. }
  27. }
  28. }
  29. return false;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement