|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--structure.AbstractIterator
|
+--structure.BTInorderIterator
An iterator for traversing binary trees constructed from BinaryTrees. The iterator performs minimal work before traversal. Every node is considered after every left descendant, but before any right descendant. AbstractIterator finishes when all descendants of the start node have been considered.
Example usage:
BinaryTree t = new BinaryTree();
// ...tree is grown
Iterator ti = t.inorderIterator();
while (ti.hasNext())
{
System.out.println(ti.next());
}
ti.reset();
while (ti.hasNext())
{ .... }
| Field Summary | |
protected BinaryTree |
root
The root of the subtree being traversed. |
protected Stack |
todo
Stack of nodes that maintain the state of the iterator. |
| Constructor Summary | |
BTInorderIterator(BinaryTree root)
Construct a new inorder iterator of a tree. |
|
| Method Summary | |
java.lang.Object |
get()
Return the node currently being considered. |
boolean |
hasNext()
Returns true iff the iterator has more nodes to be considered. |
java.lang.Object |
next()
Return current node, and increment iterator. |
void |
reset()
Reset the iterator to its initial state. |
| Methods inherited from class structure.AbstractIterator |
hasMoreElements, nextElement, remove, value |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected BinaryTree root
protected Stack todo
| Constructor Detail |
public BTInorderIterator(BinaryTree root)
root - The root of the subtree to be traversed.| Method Detail |
public void reset()
reset in class AbstractIteratorpublic boolean hasNext()
hasNext in interface java.util.IteratorhasNext in class AbstractIteratorAbstractIterator.hasMoreElements()public java.lang.Object get()
get in class AbstractIteratorpublic java.lang.Object next()
next in interface java.util.Iteratornext in class AbstractIteratorAbstractIterator.hasMoreElements(),
AbstractIterator.value()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||