1 /* $NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $
4 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
5 * the AT&T man page says.
7 * Written by reading the System V Interface Definition, not the code.
9 * Totally public domain.
12 #define _SEARCH_PRIVATE
16 static __MINGW_ATTRIB_NONNULL(1) __MINGW_ATTRIB_NONNULL(2)
17 void trecurse (const node_t *, void (*)(const void *, VISIT, int), int);
20 ( const node_t *root, void (*action)(const void *, VISIT, int), int level)
22 /* Recursively walk the nodes of a tree, performing the specified
23 * action as each node is traversed, and as appropriate for each
26 if( (root->llink == NULL) && (root->rlink == NULL) )
27 (*action) (root, leaf, level);
30 { (*action) (root, preorder, level);
31 if( root->llink != NULL )
32 trecurse (root->llink, action, level + 1);
33 (*action) (root, postorder, level);
34 if( root->rlink != NULL)
35 trecurse (root->rlink, action, level + 1);
36 (*action) (root, endorder, level);
40 void twalk (const void *root, void (*action)(const void *, VISIT, int))
42 /* Walk the nodes of a tree, delegating to the local recursive
43 * helper function, to invoke the specified action on each node
44 * in turn, as appropriate in each phase of traversal.
46 if( (root != NULL) && (action != NULL) )
47 trecurse (root, action, 0);