www.delorie.com/gnu/docs/avl/libavl_68.html   search  
Buy GNU books!

GNU libavl 2.0.1

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.11.2 Aside: Recursive Destruction

The algorithm used in the previous section is easy and fast, but it is not the most common method for destroying a tree. The usual way is to perform a traversal of the tree, in much the same way we did for tree traversal and copying. Once again, we'll start from a recursive implementation, because these are so easy to write. The only tricky part is that subtrees have to be freed before the root. This code is hard-wired to use free() for simplicity:

static void 
bst_destroy_recursive (struct bst_node *node)
{ if (node == NULL) return; bst_destroy_recursive (node-&#62;bst_link[0]); bst_destroy_recursive (node-&#62;bst_link[1]); free (node); }

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003