private static <L> void traversalHelper(Tree<L> tree, List<Tree<L>> traversal, boolean preOrder) { if (preOrder) traversal.add(tree); for (Tree<L> child : tree.getChildren()) { traversalHelper(child, traversal, preOrder); } if (!preOrder) traversal.add(tree); }
/* Returns a list of the node values gotten by traversing in this * order: left subtree, right subtree, root */ public List<Tree<L>> getPostOrderTraversal() { ArrayList<Tree<L>> traversal = new ArrayList<Tree<L>>(); traversalHelper(this, traversal, false); return traversal; }