structure
Class SplayTreeIterator

java.lang.Object
  |
  +--structure.AbstractIterator
        |
        +--structure.SplayTreeIterator
All Implemented Interfaces:
java.util.Enumeration, java.util.Iterator

class SplayTreeIterator
extends AbstractIterator

An iterator for traversing splay trees constructed from BinaryTrees. The iterator performs minimal work before traversal. Every node is considered after every left descendant, but before any right descendant. SplayTreeIterator finishes when all descendants of the start node have been considered.

Example usage:

      SplayTree t = new SplayTree();
      // ...tree is grown
      Iterator ti = t.iterator();
      while (ti.hasNext())
      {
          System.out.println(ti.next());
      }
      ti.reset();
      while (ti.hasNext())
      { .... }
 


Field Summary
protected  BinaryTree current
          The current node being considered in tree.
protected  BinaryTree tree
          A reference to the root of a splay tree.
 
Constructor Summary
SplayTreeIterator(BinaryTree root)
          Construct an iterator that traverses the binary search tree based at the root.
 
Method Summary
 java.lang.Object get()
          Return a reference to the current value.
 boolean hasNext()
          Determine if the iterator has more nodes to be considered.
 java.lang.Object next()
          Returns reference to the current element, and increments iterator.
 void reset()
          Reset the iterator to reference the root of the tree.
 
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

tree

protected BinaryTree tree
A reference to the root of a splay tree.


current

protected BinaryTree current
The current node being considered in tree.

Constructor Detail

SplayTreeIterator

public SplayTreeIterator(BinaryTree root)
Construct an iterator that traverses the binary search tree based at the root.

Parameters:
root - The root of the subtree to be traversed.
Method Detail

reset

public void reset()
Reset the iterator to reference the root of the tree.

Specified by:
reset in class AbstractIterator

hasNext

public boolean hasNext()
Determine if the iterator has more nodes to be considered.

Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in class AbstractIterator
Returns:
True iff the iterator has more nodes to be considered.
See Also:
AbstractIterator.hasMoreElements()

next

public java.lang.Object next()
Returns reference to the current element, and increments iterator.

Specified by:
next in interface java.util.Iterator
Specified by:
next in class AbstractIterator
Returns:
The reference to the current element before incrementing.
See Also:
AbstractIterator.hasMoreElements(), AbstractIterator.value()

get

public java.lang.Object get()
Return a reference to the current value.

Specified by:
get in class AbstractIterator
Returns:
A reference to the current value.