I am doing some extra work in my computer science class trying to get better at understanding the logic of data structures. Specifically, I am trying to write a remove function for a sorted binary tree:
private boolean remove(Node cRoot, Object o) {
if (cRoot == null) {
return false;
}
else if (cRoot.item.equals(o)) {
//erase node fix tree
return true;
}
else if (((Comparable)item).compareTo(cRoot.item)<=0){
return remove(cRoot.lChild, o);
}
else {
return remove(cRoot.rChild,o);
}
}
I am unsure how to go about writing the "erase node fix tree" part of the code. Mainly how many cases are there and how do I tackle them?