I've been stuck on this part of my coding assignment dealing with AVL trees. We are supposed to remove members from the AVL tree. I've been able to deal with all the other cases of removing leafs from the tree. My problem is what to do when removing the head leaf (or parent?) of the tree.
To keep it simple, I am trying to remove B from the tree. In the struct of my class, I have access to the parent and the left and right child.
B
/ \
A C
I have a method that computes the predecessor, which is A in this case. Node is the node is to be removed (B) From there, I am trying this code, but keep getting segfaults. This follows the general code which I used to remove other leafs in the tree.
successor->right = node->right;
node->right->parent = successor;
successor->parent = NULL;
node = NULL;
delete node;
delete NULL;will do nothing, because the default deleter will contain a check for NULL. - Anthony