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