public TreeNode nextElement() { Enumeration enumer = stack.peek(); TreeNode node = (TreeNode) enumer.nextElement(); Enumeration children = node.children(); if (!enumer.hasMoreElements()) { stack.pop(); } if (children.hasMoreElements()) { stack.push(children); } return node; }
public TreeNode nextElement() { try { return stack.pop(); } catch (EmptyStackException e) { throw new NoSuchElementException("No more elements"); } }
public PathBetweenNodesEnumeration(TreeNode ancestor, TreeNode descendant) { super(); if (ancestor == null || descendant == null) { throw new IllegalArgumentException("argument is null"); } TreeNode current; stack = new Stack<TreeNode>(); stack.push(descendant); current = descendant; while (current != ancestor) { current = current.getParent(); if (current == null && descendant != ancestor) { throw new IllegalArgumentException( "node " + ancestor + " is not an ancestor of " + descendant); } stack.push(current); } }
public boolean hasMoreElements() { return stack.size() > 0; }
public boolean hasMoreElements() { return (!stack.empty() && stack.peek().hasMoreElements()); }
public PreorderEnumeration(TreeNode rootNode) { super(); Vector<TreeNode> v = new Vector<TreeNode>(1); v.addElement(rootNode); // PENDING: don't really need a vector stack.push(v.elements()); }