Pre-order and Post-order recursive tree traversals

Thats an exciting topic heading is'nt it ;-)

A traversal is just "visiting" each node in the tree in a specific order. I'll
discuss Pre-order and Post-order traversals here. Performing an operation on each
node and an important task for many applications. What is also important is the order
in which the nodes are visited.

Here are the results of these two traversals with the tree structure show in
the picture above.

Traversals Order

Node order

Pre-order

Root -> 1 -> 2 -> 4 -> 6 -> 7 -> 5 -> 8 -> 9 -> 10 -> 3

Post-order

7 -> 6 -> 10 -> 9 -> 8 -> 5 -> 4 -> 3 -> 2 -> 1 -> Root

The Pre-order traversal starts at the root, processes the root. Then moves one node left
and processes that node. If there is not a left node it tries to move right. If there is
no right node it moves up one and tries moves right. Look at the example and follow the
path the traversal takes, its very simple once you see it.

A Post-order traversal is very similar in code to the Pre-order traversal. The difference
is that the function first moves as far left as possible and then only processes the
node. Again follow the path taken by the traversal in the example.