Scan tree structure from bottom up?

前端 未结 3 764
广开言路
广开言路 2021-02-08 10:23

If given the following tree structure or one similar to it:

\"enter

I would want t

3条回答
  •  悲&欢浪女
    2021-02-08 11:04

    This is called a post-order traversal of a tree: you print the content of all subtrees of a tree before printing the content of the node itself.

    Post-order traversal

    This can be done recursively, like this (pseudocode):

    function post_order(Tree node)
        foreach n in node.children
            post_order(n)
        print(node.text)
    

提交回复
热议问题