From: Lee W. <lw...@us...> - 2008-04-19 19:09:19
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12701/src Modified Files: tree.c Log Message: A new routine, _sysio_enumerate_tree, is added that supports pre-order, in-order, and post-order traversals of a tree with callbacks at each node. Index: tree.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/tree.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -b -B -p -r1.1 -r1.2 --- tree.c 21 Sep 2007 19:35:53 -0000 1.1 +++ tree.c 19 Apr 2008 19:09:14 -0000 1.2 @@ -174,3 +174,26 @@ _sysio_tree_delete(const void *key, } return tn; } + +/* + * Enumerate the passed tree calling the pre, in, and post routines at each + * node if they aren't NULL. + */ +void +_sysio_tree_enumerate(const struct tree_node *tn, + void (*pre)(const struct tree_node *), + void (*in)(const struct tree_node *), + void (*post)(const struct tree_node *)) +{ + + if (pre) + (*pre)(tn); + if (tn->tn_left) + _sysio_tree_enumerate(tn->tn_left, pre, in, post); + if (in) + (*in)(tn); + if (tn->tn_right) + _sysio_tree_enumerate(tn->tn_right, pre, in, post); + if (post) + (*post)(tn); +} |