Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean removeHelp(Key key, Top top, Top parent, Boolean links) {
- if (lookup(key)) {
- if (key.compareTo(top.getKey()) == Key.LT) {
- removeHelp(key, top.getLeft(), top,true);
- } else if (key.compareTo(top.getKey()) == Key.GT) {
- removeHelp(key, top.getRight(), top, false);
- } else {
- if (top.hasLeft() && top.hasRight()) {
- Top maxFromLeft = max(top.getLeft());
- top = maxFromLeft;
- removeHelp(maxFromLeft.getKey(), top.getLeft(), top, true);
- } else if (top.hasLeft()) {
- top.setKey(top.getLeft().getKey());
- removeHelp(top.getLeft().getKey(), top, top, true);
- } else if (top.hasRight()) {
- top.setKey(top.getRight().getKey());
- removeHelp(top.getRight().getKey(), top, top, false);
- } else {
- if (links) {
- parent.setLeft(null);
- } else {
- parent.setRight(null);
- }
- return true;
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement