|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.AbstractIterator | +--structure.BTPostorderIterator
This class implements a post-order traversal of a binary tree. This iterator considers every node after its non-trivial descendants.
Example usage:
BinaryTree
t = newBinaryTree()
; // ...tree is grownIterator
ti = t.postorderIterator()
; while (ti.hasNext()
) { System.out.println(ti.next()
); } ti.reset()
; while (ti.hasNext()
) { .... }
BinaryTree#PostorderElements
Field Summary | |
protected BinaryTree |
root
The root of the tree currently being traversed. |
protected Stack |
todo
The stack the maintains the state of the iterator. |
Constructor Summary | |
BTPostorderIterator(BinaryTree root)
Construct an iterator to traverse subtree rooted at root in post-order. |
Method Summary | |
java.lang.Object |
get()
Return the value of the current node. |
boolean |
hasNext()
Return true iff more nodes are to be considered in traversal. |
java.lang.Object |
next()
Return current value and increment iterator. |
void |
reset()
Reset 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 BTPostorderIterator(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 |