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); }
public List<Tree<L>> getPostOrderTraversal() { ArrayList<Tree<L>> traversal = new ArrayList<Tree<L>>(); traversalHelper(this, traversal, false); return traversal; }