jdsl.core.ref
Class InOrderIterator

java.lang.Object
  extended byjdsl.core.ref.InOrderIterator
All Implemented Interfaces:
ObjectIterator, PositionIterator

public class InOrderIterator
extends Object
implements PositionIterator

The inorder iterator gives an inorder iteration of a binary tree. Creating this iterator takes O(N) where N = the number of positions in the tree, assuming that root, rightChild, leftChild, isInternal are O(1) in the tree implementation. All other methods take O(1) time

Version:
JDSL 2.1.1
Author:
Ryan Shaun Baker, Mike Boilen (mgb)

Constructor Summary
InOrderIterator(InspectableBinaryTree tree)
          Constructs a new InOrderIterator to iterate over the given container Puts a reference to each position into the array -- takes O(N) time where N = the number of positions in the container (given assumptions discussed in header)
 
Method Summary
 Object element()
          Takes O(1) time
 boolean hasNext()
          Takes O(1) time
 Object nextObject()
          Takes O(1) time
 Position nextPosition()
          Takes O(1) time
 Object object()
          Takes O(1) time
 Position position()
          Takes O(1) time
 void reset()
          Takes O(1) time Sets the current node to the first node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InOrderIterator

public InOrderIterator(InspectableBinaryTree tree)
Constructs a new InOrderIterator to iterate over the given container Puts a reference to each position into the array -- takes O(N) time where N = the number of positions in the container (given assumptions discussed in header)

Parameters:
tree - The tree to iterate over
Method Detail

hasNext

public boolean hasNext()
Takes O(1) time

Specified by:
hasNext in interface ObjectIterator
Returns:
Whether there is at least one object still unseen

nextObject

public Object nextObject()
Takes O(1) time

Specified by:
nextObject in interface ObjectIterator
Returns:
Next object to consider

nextPosition

public Position nextPosition()
Takes O(1) time

Specified by:
nextPosition in interface PositionIterator
Returns:
Next position to consider

object

public Object object()
Takes O(1) time

Specified by:
object in interface ObjectIterator
Returns:
The object returned by the most recent next()

element

public Object element()
               throws NoSuchElementException
Takes O(1) time

Specified by:
element in interface PositionIterator
Returns:
Element of the position that would be returned by position()
Throws:
NoSuchElementException - When the iterator is in its initial, before-the-first-position state

position

public Position position()
                  throws NoSuchElementException
Takes O(1) time

Specified by:
position in interface PositionIterator
Returns:
The position returned by the most recent next()
Throws:
NoSuchElementException - When the iterator is in its initial, before-the-first-position state

reset

public void reset()
Takes O(1) time Sets the current node to the first node.

Specified by:
reset in interface ObjectIterator