private static <L> void appendYield(Tree<L> tree, List<L> yield) { if (tree.isLeaf()) { yield.add(tree.getLabel()); return; } for (Tree<L> child : tree.getChildren()) { appendYield(child, yield); } }
/* Returns a list of words at the leafs of this tree gotten by * traversing from left to right */ public List<L> getYield() { List<L> yield = new ArrayList<L>(); appendYield(this, yield); return yield; }