All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class graph.TreeIterator

java.lang.Object
   |
   +----graph.TreeIterator

public class TreeIterator
extends Object
This class represents iterators for class Tree. Iteration over objects of class Tree is essentially tree traversal. Class TreeIterator also has methods that enable changes in traversed trees in the process of traversal. Traversal of trees is implemented with using a stack of nodes. Traversals in pre-order, post-order, and traversals with multiple visits of non-terminal nodes are supported.

See Also:
Tree

Constructor Index

 o TreeIterator(Tree)
Constructs a TreeIterator to walk over the specified Tree.

Method Index

 o allorder()
Iterates to the next tree node by going through all edges first forward and then backward.
 o current()
Returns the currently visited node of the traversed Tree.
 o isPost()
Returns true if the currently visited node is not a leaf node and it is the last visit of this node.
 o isPre()
Returns true if the currently visited node is not a leaf node and it is the first visit of this node.
 o pop()
Forces to walk to the parent of the currently visited node.
 o postorder()
Iterates to the next tree node in post-order.
 o preorder()
Iterates to the next tree node in pre-order.
 o push(int)
Forces to walk to the child with the specified index from the currently visited node.
 o skip()
Forces to skip visiting of yet unvisited children of the currently visited node.
 o substitute(Tree)
Substitutes the specified Tree for the currently visited node in the traversed tree.
 o substituteCopy(Tree)
Substitutes a copy of the specified Tree for the currently visited node in the traversed tree.
 o visit()
Returns a number specifying the current visit.

Constructors

 o TreeIterator
 public TreeIterator(Tree p)
Constructs a TreeIterator to walk over the specified Tree.

Parameters:
p - tree to traverse

Methods

 o visit
 public int visit()
Returns a number specifying the current visit. It returns the ordinal number of the current visit for all-order traversals. If this is the last visit, lastIndex()+1 is returned for non-terminal nodes. This method always returns 1 for pre-order. It returns lastIndex()+1 when walking non-terminal nodes in post-order. This method is useful when doing all-order traversals visit non-terminal tree nodes several times.

 o isPre
 public boolean isPre()
Returns true if the currently visited node is not a leaf node and it is the first visit of this node. Returns false otherwise.

 o isPost
 public boolean isPost()
Returns true if the currently visited node is not a leaf node and it is the last visit of this node. Returns false otherwise.

 o skip
 public void skip()
Forces to skip visiting of yet unvisited children of the currently visited node. Note that the current node shall not be modified between skip() and the following iterator invocation. Otherwise, there is no guarantee that children of this node are skipped.

 o preorder
 public synchronized Tree preorder()
Iterates to the next tree node in pre-order.

 o postorder
 public synchronized Tree postorder()
Iterates to the next tree node in post-order.

 o allorder
 public synchronized Tree allorder()
Iterates to the next tree node by going through all edges first forward and then backward. Therefore, each node is visited before visiting the first child and then after visiting each child. Terminal nodes are visited once.

 o current
 public Tree current()
Returns the currently visited node of the traversed Tree.

 o pop
 public synchronized void pop()
Forces to walk to the parent of the currently visited node.

 o push
 public synchronized void push(int n)
Forces to walk to the child with the specified index from the currently visited node.

Parameters:
n - index of the child to push onto the traversal stack
 o substitute
 public synchronized void substitute(Tree r)
Substitutes the specified Tree for the currently visited node in the traversed tree. The substituted Tree becomes the latest visited node. The parameter should not be a subtree unless it is a subtree of the currently visited node.

Parameters:
p - tree that replaces the currently visited node
Throws: RuntimeException
the currently visited node is a root, or an attempt is made to substitute at an intermediate visit (neither first nor last), or an attempt is made to substitute a subtree which is not a part of the tree rooted at the currently visited node
 o substituteCopy
 public synchronized void substituteCopy(Tree u)
Substitutes a copy of the specified Tree for the currently visited node in the traversed tree. The substituted Tree becomes the latest visited node.

Parameters:
u - tree whose copy replaces the currently visited node
Throws: RuntimeException
the currently visited node is a root, or an attempt is made to substitute at an intermediate visit (neither first nor last)

All Packages  Class Hierarchy  This Package  Previous  Next  Index