1 /* $NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $ */
2 /* $FreeBSD: src/lib/libc/stdlib/twalk.c,v 1.1.2.1 2000/08/17 07:38:39 jhb Exp $ */
5 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
6 * the AT&T man page says.
8 * The node_t structure is for internal use only, lint doesn't grok it.
10 * Written by reading the System V Interface Definition, not the code.
12 * Totally public domain.
15 #include <sys/cdefs.h>
16 #if defined(LIBC_SCCS) && !defined(lint)
17 __RCSID("$NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $");
18 #endif /* LIBC_SCCS and not lint */
21 #define _SEARCH_PRIVATE
25 static void trecurse __P((const node_t *,
26 void (*action)(const void *, VISIT, int), int level));
28 /* Walk the nodes of a tree */
30 trecurse(root, action, level)
31 const node_t *root; /* Root of the tree to be walked */
32 void (*action) __P((const void *, VISIT, int));
36 if (root->llink == NULL && root->rlink == NULL)
37 (*action)(root, leaf, level);
39 (*action)(root, preorder, level);
40 if (root->llink != NULL)
41 trecurse(root->llink, action, level + 1);
42 (*action)(root, postorder, level);
43 if (root->rlink != NULL)
44 trecurse(root->rlink, action, level + 1);
45 (*action)(root, endorder, level);
49 /* Walk the nodes of a tree */
52 const void *vroot; /* Root of the tree to be walked */
53 void (*action) __P((const void *, VISIT, int));
55 if (vroot != NULL && action != NULL)
56 trecurse(vroot, action, 0);