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 * The node_t structure is for internal use only, lint doesn't grok it.
9 * Written by reading the System V Interface Definition, not the code.
11 * Totally public domain.
15 #define _SEARCH_PRIVATE
16 #include <tsearch/search.h>
19 static void trecurse (const node_t
*, void (*action
)(const void *, VISIT
, int),
20 int level
) __MINGW_ATTRIB_NONNULL (1)
21 __MINGW_ATTRIB_NONNULL (2);
22 /* Walk the nodes of a tree */
24 trecurse( const node_t
*root
, /* Root of the tree to be walked */
25 void (*action
)(const void *, VISIT
, int),
28 if (root
->llink
== NULL
&& root
->rlink
== NULL
)
29 (*action
)(root
, leaf
, level
);
31 (*action
)(root
, preorder
, level
);
32 if (root
->llink
!= NULL
)
33 trecurse(root
->llink
, action
, level
+ 1);
34 (*action
)(root
, postorder
, level
);
35 if (root
->rlink
!= NULL
)
36 trecurse(root
->rlink
, action
, level
+ 1);
37 (*action
)(root
, endorder
, level
);
41 /* Walk the nodes of a tree */
43 twalk( const void *vroot
, /* Root of the tree to be walked */
44 void (*action
) (const void *, VISIT
, int))
46 if (vroot
!= NULL
&& action
!= NULL
)
47 trecurse(vroot
, action
, 0);