structure
Class DoublyLinkedListIterator<ELTTYPE>

java.lang.Object
  extended by structure.AbstractIterator<ELTTYPE>
      extended by structure.DoublyLinkedListIterator<ELTTYPE>
All Implemented Interfaces:
java.util.Enumeration<ELTTYPE>, java.util.Iterator<ELTTYPE>

public class DoublyLinkedListIterator<ELTTYPE>
extends AbstractIterator<ELTTYPE>

An iterator for traversing the elements of a doubly linked list. The iterator traverses the list beginning at the head, and heads toward tail. Typical use:

      List l = new DoublyLinkedList();
      // ...list gets built up...
      Iterator li = l.iterator();
      while (li.hasNext())
      {
          System.out.println(li.get());
          li.next();
      }
      li.reset();
      while (li.hasNext())
      { .... }
 


Constructor Summary
DoublyLinkedListIterator(DoublyLinkedListElement<ELTTYPE> h)
          Construct an iterator over a doubly linked list hanging from head.
DoublyLinkedListIterator(DoublyLinkedListElement<ELTTYPE> headDummy, DoublyLinkedListElement<ELTTYPE> tailDummy)
           
 
Method Summary
 ELTTYPE get()
          Get reference to value that is current.
 boolean hasNext()
          Determine if there are more elements to be considered.
 ELTTYPE next()
          Returns reference to the current element, then increments iterator.
 void reset()
          Reset the iterator to the head of the list.
 
Methods inherited from class structure.AbstractIterator
hasMoreElements, nextElement, remove, value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoublyLinkedListIterator

public DoublyLinkedListIterator(DoublyLinkedListElement<ELTTYPE> h)
Construct an iterator over a doubly linked list hanging from head.

Parameters:
h - The head of the list to be traversed.
Post:
constructs an iterator rooted at list head, h

DoublyLinkedListIterator

public DoublyLinkedListIterator(DoublyLinkedListElement<ELTTYPE> headDummy,
                                DoublyLinkedListElement<ELTTYPE> tailDummy)
Method Detail

reset

public void reset()
Reset the iterator to the head of the list.

Specified by:
reset in class AbstractIterator<ELTTYPE>
Post:
resets iterator to list head

hasNext

public boolean hasNext()
Determine if there are more elements to be considered.

Specified by:
hasNext in interface java.util.Iterator<ELTTYPE>
Specified by:
hasNext in class AbstractIterator<ELTTYPE>
Returns:
True iff there are more elements to be considered.
See Also:
AbstractIterator.hasMoreElements()
Post:
returns true iff current element is valid

next

public ELTTYPE next()
Returns reference to the current element, then increments iterator.

Specified by:
next in interface java.util.Iterator<ELTTYPE>
Specified by:
next in class AbstractIterator<ELTTYPE>
Returns:
Reference to element that was current before increment.
See Also:
AbstractIterator.hasMoreElements(), AbstractIterator.value()
Post:
returns current element and increments iterator

get

public ELTTYPE get()
Get reference to value that is current.

Specified by:
get in class AbstractIterator<ELTTYPE>
Returns:
A reference to the value that is current.
Pre:
hasNext
Post:
returns current element