Algorithm
Development Kit 1.0

algs.model.tree
Class AbstractBinaryTraversal<T extends IBinaryTreeNode>

java.lang.Object
  extended by algs.model.tree.AbstractBinaryTraversal<T>
Type Parameters:
T - Any class that extends IBinaryTreeNode can be used as the structure of a Binary tree, and thus can be used as the parameter for this traversal class.
All Implemented Interfaces:
java.util.Iterator<IBinaryTreeNode>
Direct Known Subclasses:
InorderTraversal, PostorderTraversal, PreorderTraversal

public abstract class AbstractBinaryTraversal<T extends IBinaryTreeNode>
extends java.lang.Object
implements java.util.Iterator<IBinaryTreeNode>

The default traversal class for IBinaryTree trees. Makes it possible to expose a pre-, in-, or post-order traversal as an Iterator.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Nested Class Summary
static class AbstractBinaryTraversal.Phase
          Binary traversals have three phases.
 
Constructor Summary
AbstractBinaryTraversal(T node)
          Start the traversal at the given node.
 
Method Summary
 void advance()
          Advance the traversal, returning the SELF node once found or null when all is done.
abstract  AbstractBinaryTraversal.Phase advancePhase(AbstractBinaryTraversal.Phase p)
          Determine the next phase in the traversal.
abstract  AbstractBinaryTraversal.Phase finalPhase()
          Return the final phase of the traversal.
 boolean hasNext()
          Determines if there are more steps in the traversal.
abstract  AbstractBinaryTraversal.Phase initialPhase()
          Return the initial phase of the traversal.
 IBinaryTreeNode next()
          Returns the next node in the traversal.
 void remove()
          Not supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractBinaryTraversal

public AbstractBinaryTraversal(T node)
Start the traversal at the given node.

Parameters:
node -
Method Detail

initialPhase

public abstract AbstractBinaryTraversal.Phase initialPhase()
Return the initial phase of the traversal. Essential for the generic traversal routine in advance()


finalPhase

public abstract AbstractBinaryTraversal.Phase finalPhase()
Return the final phase of the traversal. Essential for the generic traversal routine in advance()


advancePhase

public abstract AbstractBinaryTraversal.Phase advancePhase(AbstractBinaryTraversal.Phase p)
Determine the next phase in the traversal. Essential for the generic traversal routine in advance()


advance

public void advance()
Advance the traversal, returning the SELF node once found or null when all is done.


hasNext

public boolean hasNext()
Determines if there are more steps in the traversal.

Specified by:
hasNext in interface java.util.Iterator<IBinaryTreeNode>

next

public IBinaryTreeNode next()
Returns the next node in the traversal.

Specified by:
next in interface java.util.Iterator<IBinaryTreeNode>

remove

public void remove()
Not supported.

Specified by:
remove in interface java.util.Iterator<IBinaryTreeNode>

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.