public TreeNode nextElement() { Enumeration enumer = (Enumeration) queue.firstObject(); TreeNode node = (TreeNode) enumer.nextElement(); Enumeration children = node.children(); if (!enumer.hasMoreElements()) { queue.dequeue(); } if (children.hasMoreElements()) { queue.enqueue(children); } return node; }
public BreadthFirstEnumeration(TreeNode rootNode) { super(); Vector<TreeNode> v = new Vector<TreeNode>(1); v.addElement(rootNode); // PENDING: don't really need a vector queue = new Queue(); queue.enqueue(v.elements()); }
public boolean hasMoreElements() { return (!queue.isEmpty() && ((Enumeration) queue.firstObject()).hasMoreElements()); }