Easy, every node (left, right, data).
Start with the first node. execute the algorithm for the left subtree, if available, and then execute the algorithm for the right subtree and then print the data.
TreeNode = ([TreeNode], Data, [TreeNode])
TreeToPostfix: [TreeNode] -> Data*
TreeToPostfix(nil) = []
TreeToPostfix((left, data, right)) ==
TreeToPostfix(left) ++ TreeToPostfix(right) ++ Data
For example:
+
/ \
* -
/ \ / \
2 3 4 5
Produces: 2 3 * 4 5 - +
source
share