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