/** * Walks the tree in pre-order style. * @param node The starting element. * @param list The output of the walk. */ protected void walkPreorder(TreeNode node, List list) { list.add(node); List children = node.getChildren(); if(children!=null) { for(int i=0; i<children.size(); i++) { TreeNode child = (TreeNode)children.get(i); walkPreorder(child, list); } } }
/** * Walks the tree in post-order style. * @param node The starting element. * @param list The output of the walk. */ protected void walkPostorder(TreeNode node, List list) { List children = node.getChildren(); if(children!=null) { for(int i=0; i<children.size(); i++) { TreeNode child = (TreeNode)children.get(i); walkPostorder(child, list); } } list.add(node); } }
/** * Get the string representation. * @return The string representation. */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{").append(""+getData()).append(",["); List children = getChildren(); if(children!=null) { for(int i=0; i<children.size(); i++) { TreeNode node = (TreeNode)children.get(i); if(i > 0) sb.append(","); sb.append(""+node.getData()); i++; } } sb.append("]").append("}"); return sb.toString(); } }
List children = node.getChildren(); if(children!=null)
List stack = wc.getStack(); List children = node.getChildren(); for(int i=0; i<children.size(); i++)