Possible Duplicate:
Post order traversal of binary tree without recursion
I was going through the inorder traversal algorithm in a binary tree by Morris.
Can someone please suggest whether there is a way to traverse postorder without using recursion and stack?
You can do this with a threaded tree. Here’s an outline of the method (taken from here—see slide 31):
is traversed. Otherwise action changed to right traversal.
to left traversal. Otherwise action changed to visiting a node.
has to be found.
left child) then traversal is set to continue with the right descendant of parent.
of nodes.
restored to previous settings.
As the above reference goes on to show, it can also be done without threading if you use temporary modifications to the tree structure.