diff options
| author | Thomas Schmucker <ts@its1.de> | 2021-12-29 10:23:24 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2021-12-29 10:23:24 +0100 |
| commit | ab1120dac9a5096b603915f53e99642a19cbe126 (patch) | |
| tree | 62ed11adec0aa9e80ae12b435bed378fc3c33997 /treeutil.h | |
| parent | ee6f566950603d2439b8748fb03870aab6c43302 (diff) | |
| download | data-structures-ab1120dac9a5096b603915f53e99642a19cbe126.tar.gz data-structures-ab1120dac9a5096b603915f53e99642a19cbe126.tar.bz2 data-structures-ab1120dac9a5096b603915f53e99642a19cbe126.zip | |
fix: reformat code
Diffstat (limited to 'treeutil.h')
| -rw-r--r-- | treeutil.h | 38 |
1 files changed, 22 insertions, 16 deletions
| @@ -1,33 +1,38 @@ | |||
| 1 | // aux display and verification routines, helpful but not essential | 1 | // aux display and verification routines, helpful but not essential |
| 2 | struct trunk { | 2 | struct trunk { |
| 3 | struct trunk *prev; | 3 | struct trunk *prev; |
| 4 | char * str; | 4 | const char * str; |
| 5 | }; | 5 | }; |
| 6 | 6 | ||
| 7 | static void show_trunks(struct trunk *p) | 7 | static void |
| 8 | show_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 |
| 15 | static void show_tree(struct tree_node *root, struct trunk *prev, int is_left) | 17 | static void |
| 18 | show_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 | |||
