Question
Please help find mistake in my avl code for remove. Predecessor is used for remove. public T remove(T data) { if (data == null) {
Please help find mistake in my avl code for remove. Predecessor is used for remove.
public T remove(T data) {
if (data == null) {
throw new IllegalArgumentException("Cannot remove null data");
}
AVLNode
remove2(root,node,data);
return node.getData();
}
private AVLNode
if (initial == null) {
throw new java.util.NoSuchElementException("Data not found");
}
if (data.compareTo(initial.getData()) > 0) {
initial.setRight(remove2(initial.getRight(),store,data));
} else if (data.compareTo(initial.getData()) < 0) {
initial.setLeft(remove2(initial.getLeft(),store,data));
}
else {
T thing = initial.getData();
store.setData(thing);
size--;
if (initial.getLeft() != null && initial.getRight() != null) {
initial.setLeft(pred(initial.getLeft(), store));
initial.setData(store.getData());
} else if (initial.getLeft() == null) {
return initial.getRight();
} else if (initial.getRight() == null) {
return initial.getLeft();
} else {
return null;
}
}
balance(initial);
return rotate(initial);
}
private AVLNode
if (initial.getLeft() == null) {
store.setData(initial.getData());
return initial.getRight();
}
initial.setLeft(pred(initial.getLeft(), store));
balance(initial);
return rotate(initial);
}
private void balance(AVLNode
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started