示例#1
0
文件: Tree.java 项目: gkokaisel/NLP
 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
文件: Tree.java 项目: gkokaisel/NLP
 /* 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;
 }