Esempio n. 1
0
    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;
    }
Esempio n. 2
0
 public TreeNode nextElement() {
   try {
     return stack.pop();
   } catch (EmptyStackException e) {
     throw new NoSuchElementException("No more elements");
   }
 }
Esempio n. 3
0
    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);
      }
    }
Esempio n. 4
0
 public boolean hasMoreElements() {
   return stack.size() > 0;
 }
Esempio n. 5
0
 public boolean hasMoreElements() {
   return (!stack.empty() && stack.peek().hasMoreElements());
 }
Esempio n. 6
0
 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());
 }