|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.AbstractIterator | +--structure.BTLevelorderIterator
An iterator for traversing binary trees constructed from BinaryTrees. The iterator performs minimal work before traversal. Every node is considered after every non-trivial ancestor or left cousin, and before any non-trivial descendant or right cousin. LevelOrderIterator finishes when all descendants of the start node have been considered.
Example usage:
BinaryTree
t = newBinaryTree()
; // ...tree is grownIterator
ti = t.levelorderIterator()
; 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 Queue |
todo
Queue of nodes that maintain the state of the iterator. |
Constructor Summary | |
BTLevelorderIterator(BinaryTree root)
Construct a new level-order iterator of a tree. |
Method Summary | |
java.lang.Object |
get()
Returns the value of the currently considered node. |
boolean |
hasNext()
Return true if more nodes are to be considered. |
java.lang.Object |
next()
Returns currently considered value and increments iterator. |
void |
reset()
Reset iterator to beginning of 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 Queue todo
Constructor Detail |
public BTLevelorderIterator(BinaryTree root)
root
- The root of the subtree to be traversed.Method Detail |
public void reset()
reset
in class AbstractIterator
public boolean hasNext()
hasNext
in interface java.util.Iterator
hasNext
in class AbstractIterator
AbstractIterator.hasMoreElements()
public java.lang.Object get()
get
in class AbstractIterator
public java.lang.Object next()
next
in interface java.util.Iterator
next
in class AbstractIterator
AbstractIterator.hasMoreElements()
,
AbstractIterator.value()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |