This is an eclipse based project. So the attachment may be unzipped and run in eclipse.
eclipse Juno and Java 7 has been used. First the code should be inspected and run. Then the blog may be reffered.
======================================
Stack based implementation of Binary Tree traversal. The ArrayList<Integer> result variable will have the traversal result
In this example I have added the data from a node to the ArrayList.
Entry.java should be run as Java Application. This class basically tests the functionalities.
A close inspection to the code will make it easy to understand that left branch of a root is always explored before the right branch. For example: The order of stack insertion of nodes in a sub tree is the same for all three traversals.
1) Insert Root --> 2) insert until the last left child --> 3)pop until the top node of the stack has a right child--> 4) Insert Right child (This child is the new Root now, call this node as "new Root 1") -->5) Follow all the steps from 2 to 4 recursively till the top node of the stack is again "new Root 1" --> pop "new Root 1" --> pop Root
InOrder
=======
The Node data will be added to the ArrayList only in the following cases
1> When any of the leafe nodes pops, it's data/node will be added
2> Immidiately after a left child is popped, the parent's data/node will be added
3> if the parent does not have a left child, it's data/node will be added immidiately before it's right child is pushed into the stack.
PreOrder
========
After every push() operation to the stack, the data/node of the pushed node will be added.
Post Order
==========
The Node data will be added to the ArrayList only in the following cases
1> If a node does not have a right child, but has a left child, then immidiately after the left child is popped, parent's data/node
will be added (after popping the parent).
2> Immidiately after popping out the right son, the parent's data/node will be added (after popping the parent).
3> A leaf is always popped and it's data/node is added.
There should be one change and the following line in italics will be replaced by the statement in bold.