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