From 154874afda4a8df885e51c01f7681f04fb0b8e61 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sat, 9 Apr 2022 09:43:53 +0200 Subject: neue Verzeichnisstruktur --- src/treeutil.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/treeutil.h (limited to 'src/treeutil.h') 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 @@ +// aux display and verification routines, helpful but not essential +struct trunk { + struct trunk *prev; + const char * str; +}; + +static void +show_trunks(struct trunk *p) +{ + if ( !p ) + return; + show_trunks(p->prev); + printf("%s", p->str); +} + +// this is very haphazzard +static void +show_tree(struct tree_node *root, struct trunk *prev, int is_left) +{ + if ( root == NULL ) + return; + + struct trunk this_disp = { prev, " " }; + const char * prev_str = this_disp.str; + show_tree(root->right, &this_disp, 1); + + if ( !prev ) + this_disp.str = "---"; + else if ( is_left ) { + this_disp.str = ".--"; + prev_str = " |"; + } + else { + this_disp.str = "`--"; + prev->str = prev_str; + } + + show_trunks(&this_disp); + if ( root->key >= 'A' && root->key <= 'Z' ) + printf("%c\n", root->key); + else + printf("%d\n", root->key); + + if ( prev ) + prev->str = prev_str; + this_disp.str = " |"; + + show_tree(root->left, &this_disp, 0); + if ( !prev ) + puts(""); +} -- cgit v1.3