Пример #1
0
 public TreeNode nextElement() {
   try {
     return stack.pop();
   } catch (EmptyStackException e) {
     throw new NoSuchElementException("No more elements");
   }
 }
Пример #2
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;
    }