aboutsummaryrefslogtreecommitdiff
path: root/src/treeutil.h
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2022-04-09 09:43:53 +0200
committerThomas Schmucker <ts@its1.de>2022-04-09 09:43:53 +0200
commit154874afda4a8df885e51c01f7681f04fb0b8e61 (patch)
tree274817eb2793584b0e3d856de5504a614f2b4e89 /src/treeutil.h
parent2863f4f1d2a6a6a8704454824d6c291d2e0d4b5c (diff)
downloaddata-structures-154874afda4a8df885e51c01f7681f04fb0b8e61.tar.gz
data-structures-154874afda4a8df885e51c01f7681f04fb0b8e61.tar.bz2
data-structures-154874afda4a8df885e51c01f7681f04fb0b8e61.zip
neue Verzeichnisstruktur
Diffstat (limited to 'src/treeutil.h')
-rw-r--r--src/treeutil.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/treeutil.h b/src/treeutil.h
new file mode 100644
index 0000000..76627c0
--- /dev/null
+++ b/src/treeutil.h
@@ -0,0 +1,51 @@
1// aux display and verification routines, helpful but not essential
2struct trunk {
3 struct trunk *prev;
4 const char * str;
5};
6
7static void
8show_trunks(struct trunk *p)
9{
10 if ( !p )
11 return;
12 show_trunks(p->prev);
13 printf("%s", p->str);
14}
15
16// this is very haphazzard
17static void
18show_tree(struct tree_node *root, struct trunk *prev, int is_left)
19{
20 if ( root == NULL )
21 return;
22
23 struct trunk this_disp = { prev, " " };
24 const char * prev_str = this_disp.str;
25 show_tree(root->right, &this_disp, 1);
26
27 if ( !prev )
28 this_disp.str = "---";
29 else if ( is_left ) {
30 this_disp.str = ".--";
31 prev_str = " |";
32 }
33 else {
34 this_disp.str = "`--";
35 prev->str = prev_str;
36 }
37
38 show_trunks(&this_disp);
39 if ( root->key >= 'A' && root->key <= 'Z' )
40 printf("%c\n", root->key);
41 else
42 printf("%d\n", root->key);
43
44 if ( prev )
45 prev->str = prev_str;
46 this_disp.str = " |";
47
48 show_tree(root->left, &this_disp, 0);
49 if ( !prev )
50 puts("");
51}