Removing from a binary three has three scenarios.

  1. The node is a leaf
  2. The node has a sub-tree connected to either the left OR the right
  3. 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

  1. All children of the node being removed are removed and added to a stack
  2. The node to be removed is removed!
  3. All of the nodes are readdded from the stack.