Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 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 (parent == null) {
  22. root = top.getLeft();
  23. }
  24. else if(links) {
  25. parent.setLeft(top.getLeft());
  26. } else {
  27. parent.setRight(top.getLeft());
  28. }
  29. } else if (top.hasRight()) {
  30. if (parent == null) {
  31. root = top.getRight();
  32. }
  33. if(links) {
  34. parent.setLeft(top.getRight());
  35. } else {
  36. parent.setRight(top.getRight());
  37. }
  38. } else {
  39. if (links) {
  40. parent.setLeft(null);
  41. } else {
  42. parent.setRight(null);
  43. }
  44. return true;
  45. }
  46. }
  47. }
  48. return false;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement