You can do this with a threaded tree. Here's an outline of the method (taken from here—see slide 31):
- Postorder: a dummy node created that has root as left descendant.
- A variable can be used to check type of current action.
- If action is left traversal and current node has a left descendant, then descendant
is traversed. Otherwise action changed to right traversal.
- If action is right traversal and current node has a left descendant, action changed
to left traversal. Otherwise action changed to visiting a node.
- If action is visiting node: current node is visited, afterwards its postorder successor
has to be found.
- If current node’s parent accessible through a thread (i.e. current node is parent’s
left child) then traversal is set to continue with the right descendant of parent.
- If current node has no right descendant, this is the end of the right-extended chain
of nodes.
- First: the beginning of the chain is reached through the thread of the current node.
- Second: right references of nodes in the chain is reversed.
- Finally: chain is scanned backward, each node is visited, then right references are
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.