Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 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. if(parent == null) {
  11. root = maxFromLeft;
  12. } else if(links) {
  13. parent.setLeft(maxFromLeft);
  14. } else {
  15. parent.setRight(maxFromLeft);
  16. }
  17. removeHelp(maxFromLeft.getKey(), top.getLeft(), top, true);
  18. maxFromLeft.setRight(top.getRight());
  19. maxFromLeft.setLeft(top.getLeft());
  20. } else if (top.hasLeft()) {
  21. if(links) {
  22. parent.setLeft(top.getLeft());
  23. } else {
  24. parent.setRight(top.getLeft());
  25. }
  26. } else if (top.hasRight()) {
  27. if(links) {
  28. parent.setLeft(top.getRight());
  29. } else {
  30. parent.setRight(top.getRight());
  31. }
  32. } else {
  33. if (links) {
  34. parent.setLeft(null);
  35. } else {
  36. parent.setRight(null);
  37. }
  38. return true;
  39. }
  40. }
  41. }
  42. return false;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement