1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "tree.h"
4
5 struct tree {
6 int id;
7 TREE_NODE(tree) link;
8 };
9
10 int
main(int argc,char ** argv)11 main (int argc, char **argv)
12 {
13 struct tree nodes[10];
14 TREE_SCRATCH(tree, 10) scratch;
15 int i;
16
17 struct tree *walk;
18
19 for (i = 0; i < 10; i++) {
20 nodes[i].id = i;
21 TREE_INIT_NODE(&nodes[i], link);
22 }
23
24 TREE_INSERT_CHILD(&nodes[0], &nodes[1], link);
25 TREE_INSERT_CHILD(&nodes[1], &nodes[2], link);
26 TREE_INSERT_CHILD(&nodes[1], &nodes[3], link);
27 TREE_INSERT_CHILD(&nodes[2], &nodes[4], link);
28 TREE_INSERT_CHILD(&nodes[3], &nodes[5], link);
29
30 TREE_DFS_FOREACH(walk, &nodes[0], &scratch, link)
31 printf("DFS: %d\n", walk->id);
32
33 TREE_BFS_FOREACH(walk, &nodes[0], &scratch, link)
34 printf("BFS: %d\n", walk->id);
35
36 return 0;
37 }
38