“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”
My solution demands a lot of extra space, but here it goes. I’m assuming each node holds one printable character, you can abstract this algorithm to hold whatever you want.
char levels_char_buffer[MAX_LEVELS][MAX_BUFFER]; //hold the information for each level of the tree.
Use recursion to print in post-order for the binary tree.
My solution demands a lot of extra space, but here it goes. I’m assuming each node holds one printable character, you can abstract this algorithm to hold whatever you want.
char levels_char_buffer[MAX_LEVELS][MAX_BUFFER]; //hold the information for each level of the tree.
void print_tree_level( tree* treep, int level)
{
strcat( levels_char_buffer[ level], p->data);
print_tree_level( treep->leftp, level+1);
print_tree_level( treep->rightp, level+1);
}
void print_tree( tree* treep)
{
memset( level_char_buffer, ‘