Binary tree - overview |
Removing from a binary three has three scenarios.
- The node is a leaf
- The node has a sub-tree connected to either the left OR the right
- The node has a sub-tree connect to both the left AND right
Node is a leaf
The parent node will have its link removed and the pointer set to null. The node is then deleted.
The node has one sub-tree
The parent node will have its pointer changed to point to the child of the node being removed.
The node has two sub-trees
- All children of the node being removed are removed and added to a stack
- The node to be removed is removed!
- All of the nodes are readdded from the stack.