private TreeNode<?> traverse(Enumeration children) { if (children.hasMoreElements()) { TreeNode<?> node = (TreeNode<?>) children.nextElement(); nodes.push(node); Enumeration newChildren = Collections.enumeration(node.getChildren()); childrenEnums.push(newChildren); return traverse(newChildren); } else { childrenEnums.pop(); TreeNode<?> next = nodes.peek(); nodes.pop(); return next; } }
private TreeNode<?> traverse(Enumeration children) { // If more children are available step down. if (children.hasMoreElements()) { TreeNode<?> child = (TreeNode<?>) children.nextElement(); childrenEnums.push(Collections.enumeration(child.getChildren())); return child; } // If no children are left, we return to a higher level. childrenEnums.pop(); // If there are no more levels left, there is no next // element to return. if (childrenEnums.isEmpty()) return null; else { return traverse((Enumeration) childrenEnums.peek()); } }
PostOrderEnumeration(TreeNode<?> node) { nodes.push(node); childrenEnums.push(Collections.enumeration(node.getChildren())); }
public boolean equals(TreeNode<T> node) { return node.getData().equals(getData()); }
PreOrderEnumeration(TreeNode<?> node) { next = node; childrenEnums.push(Collections.enumeration(node.getChildren())); }