I'm planning on writing a program that will display a binary tree of a small height like so:
The best way I could think of was to place the root in a queue, then loop until the queue is empty placing the left and right children at the end of the queue and then printing and popping the front. Something like:
/ \ / \
3 4 5 1
/ \ / \ / \ / \
2 6 1 9 6 8 7 6
The problem with this idea though is that it doesn't account for empty spots, so would mess up with something like:
Any ideas how to get around this? My brain is kinda fried at the moment unfortunately...