Commit 6457da18 by Rudolf

Add print tree support (horizontal)

Horizontal tree print fills all my needs
parent a169c230
Showing with 32 additions and 0 deletions
......@@ -44,3 +44,32 @@ void print_char(char c)
break;
}
}
void print_tree(struct tree *parent)
{
int level = 1;
while (parent->left != NULL ) {
for (int i = 0; i < level; i++) {
printf(" ");
}
if (parent->right)
print_char(parent->right->ch);
for (int i = 0; i < level-1; i++) {
printf(" ");
}
printf("o\n");
for (int i = 0; i < level; i++) {
printf(" ");
}
if (parent->left && parent->left->ch != 0)
print_char(parent->left->ch);
else
printf("o\n");
level += 2;
parent = parent->left;
}
}
/* I DO NOT OWN THIS CODE. */
/* From http://stackoverflow.com/questions/111928/is-there-a-printf-converter-to-print-in-binary-format?page=2&tab=votes#tab-top */
#include "tree.h"
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define for_endian(size) for (int i = 0; i < size; ++i)
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
......@@ -18,3 +20,4 @@ void __printb(void *value, size_t size);
})
void print_char(char c);
void print_tree(struct tree *parent);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment