aboutsummaryrefslogtreecommitdiff
path: root/treeutil.h
diff options
context:
space:
mode:
Diffstat (limited to 'treeutil.h')
-rw-r--r--treeutil.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/treeutil.h b/treeutil.h
new file mode 100644
index 0000000..302a6e3
--- /dev/null
+++ b/treeutil.h
@@ -0,0 +1,45 @@
1// aux display and verification routines, helpful but not essential
2struct trunk {
3 struct trunk *prev;
4 char * str;
5};
6
7static void show_trunks(struct trunk *p)
8{
9 if (!p) return;
10 show_trunks(p->prev);
11 printf("%s", p->str);
12}
13
14// this is very haphazzard
15static void show_tree(struct tree_node *root, struct trunk *prev, int is_left)
16{
17 if (root == NULL) return;
18
19 struct trunk this_disp = { prev, " " };
20 char *prev_str = this_disp.str;
21 show_tree(root->right, &this_disp, 1);
22
23 if (!prev)
24 this_disp.str = "---";
25 else if (is_left) {
26 this_disp.str = ".--";
27 prev_str = " |";
28 } else {
29 this_disp.str = "`--";
30 prev->str = prev_str;
31 }
32
33 show_trunks(&this_disp);
34 if ( root->key >= 'A' && root->key <= 'Z' )
35 printf("%c\n", root->key);
36 else
37 printf("%d\n", root->key);
38
39 if (prev) prev->str = prev_str;
40 this_disp.str = " |";
41
42 show_tree(root->left, &this_disp, 0);
43 if (!prev) puts("");
44}
45