Java – scan tree structure from bottom to top?
•
Java
If the following tree structure or similar structure is given:
I want to return the string zyxwvut I know how to do this using a binary tree, but I can't use multiple child nodes Any help would be appreciated
Solution
This is called post order traversal of a tree: print the contents of all subtrees of the tree before printing the contents of the node itself
This can be done recursively, like this (pseudo code):
function post_order(Tree node) foreach n in node.children post_order(n) print(node.text)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码