jdsl.core.ref
Class InOrderIterator

java.lang.Object
  |
  +--jdsl.core.ref.InOrderIterator

public class InOrderIterator
extends java.lang.Object

The inorder iterator tells what, for an inorder traversal of the tree, the first, last, next, prev elements are, and can output a whole traversal of the tree, including the leaves.

Author:
Ryan Shaun Baker, Mike Boilen (mgb)

Constructor Summary
InOrderIterator(InspectableBinaryTree tree)
          Constructs a new InOrderIterator to iterate the given container
 
Method Summary
 Position current()
          Gets the current Position
 Position first()
          The first position in the in-order traversal
 Position last()
          The last position in the in-order traversal
 Position next()
          Gets the next Position
 Position prev()
          Returns the in-order-previous of the given locator, including the leafs Throws a BoundaryViolationException if c is the first node in inorder traversal
 void setCurrent(Position newCurrent)
          Sets the Iterator's current Locator to newCurrent.
 Sequence traversal()
          Generates the inorder traversal of the tree.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InOrderIterator

public InOrderIterator(InspectableBinaryTree tree)
Constructs a new InOrderIterator to iterate the given container
Parameters:
tree -  
Method Detail

current

public Position current()
Gets the current Position
Returns:
the current Position.

setCurrent

public void setCurrent(Position newCurrent)
Sets the Iterator's current Locator to newCurrent.
Parameters:
newCurrent - the Iterator's new current Locator

next

public Position next()
              throws BoundaryViolationException
Gets the next Position
Throws:
BoundaryViolationException - If the iterator is at the last Position.

prev

public Position prev()
              throws BoundaryViolationException
Returns the in-order-previous of the given locator, including the leafs Throws a BoundaryViolationException if c is the first node in inorder traversal
Returns:
the in-order-previous of the given locator, including the leaves
Throws:
BoundaryViolationException - if called when at the beginning of the tree.

first

public Position first()
The first position in the in-order traversal
Returns:
a locator to the in-order-first element of the tree, which is a leaf goes from left child to left child until reaching a leaf.

last

public Position last()
The last position in the in-order traversal
Returns:
a locator to the in-order-last element of the tree, which is a leaf goes from right child to right child until reaching a leaf.

traversal

public Sequence traversal()
Generates the inorder traversal of the tree.
Returns:
the inorder sequence of locators to the internal AND leaf nodes of the tree