Scan tree structure from bottom up?

algorithm, java, tree

Solution

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.

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

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

Problem

If given the following tree structure or one similar to it: I would want the string ZYXWVUT returned. I know how to do this with a binary tree but not one that can have more than child nodes. Any help would be much appreciated.

Original source