Пример #1
0
    private TreeNode<?> traverse(Enumeration children) {
      if (children.hasMoreElements()) {
        TreeNode<?> node = (TreeNode<?>) children.nextElement();
        nodes.push(node);

        Enumeration newChildren = Collections.enumeration(node.getChildren());
        childrenEnums.push(newChildren);

        return traverse(newChildren);
      } else {
        childrenEnums.pop();
        TreeNode<?> next = nodes.peek();
        nodes.pop();
        return next;
      }
    }
Пример #2
0
    private TreeNode<?> traverse(Enumeration children) {
      // If more children are available step down.
      if (children.hasMoreElements()) {
        TreeNode<?> child = (TreeNode<?>) children.nextElement();
        childrenEnums.push(Collections.enumeration(child.getChildren()));

        return child;
      }

      // If no children are left, we return to a higher level.
      childrenEnums.pop();

      // If there are no more levels left, there is no next
      // element to return.
      if (childrenEnums.isEmpty()) return null;
      else {
        return traverse((Enumeration) childrenEnums.peek());
      }
    }
Пример #3
0
 PostOrderEnumeration(TreeNode<?> node) {
   nodes.push(node);
   childrenEnums.push(Collections.enumeration(node.getChildren()));
 }
Пример #4
0
 public boolean equals(TreeNode<T> node) {
   return node.getData().equals(getData());
 }
Пример #5
0
 PreOrderEnumeration(TreeNode<?> node) {
   next = node;
   childrenEnums.push(Collections.enumeration(node.getChildren()));
 }