|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--structure.AbstractIterator
|
+--structure.BTPreorderIterator
This class implements an iterator that traverses a tree in pre-order. Each node is considered before its descendants.
Example usage:
BinaryTree t = new BinaryTree();
// ...tree is grown
Iterator ti = t.preorderIterator();
while (ti.hasNext())
{
System.out.println(ti.next());
}
ti.reset();
while (ti.hasNext())
{ .... }
| Field Summary | |
protected BinaryTree |
root
The root of the subtree to be considered by traversal. |
protected Stack |
todo
The stack that maintains the state of the iterator. |
| Constructor Summary | |
BTPreorderIterator(BinaryTree root)
Constructs a pre-order traversal of subtree rooted at root. |
|
| Method Summary | |
java.lang.Object |
get()
Returns the value currently being referenced by iterator. |
boolean |
hasNext()
Returns true if some nodes of subtree have yet to be considered. |
java.lang.Object |
next()
Returns the current value and increments the iterator. |
void |
reset()
Resets the iterator to the first node of the traversal. |
| 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 BTPreorderIterator(BinaryTree root)
root - Root of 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 | ||||||||