Clearing the tree is a useful operation and it helps us to understand the recursive structure of the algorithms presented here. The procedure receives a node T that traverses the tree downward starting from left until it reaches its lowest level. It then traverses the subtree at the right, deleting a node whenever it reaches a NIL node in the bottom. This particular procedure performs what is known as post-order traversal, because it first goes through both the left and right subtrees before reaching back the root.

TREE_CLEAR (value)
1.    if (x <> NIL) then
2.    begin
3.      TREE_CLEAR(x->left);
4.      TREE_CLEAR(x->right);
5.      DELETE(x);
6.    endif
7.  end.

Previous Page
Next Page
Return to Main Page