您可以使用 < a href=> "" "http://en.wikipedia.org/wiki/Threaded_binary_tree" rel="nofollow">经读的树 。这里是方法的大纲(取自):
- 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.
如上所述,如果对树结构进行临时修改,也可以不进行线性调整。