structure5
Class DoublyLinkedListIterator<E>

java.lang.Object
  extended by structure5.AbstractIterator<E>
      extended by structure5.DoublyLinkedListIterator<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Enumeration<E>, java.util.Iterator<E>

public class DoublyLinkedListIterator<E>
extends AbstractIterator<E>

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())
      { .... }
 


Field Summary
protected  DoublyLinkedNode<E> current
          Reference to the current node in the list.
protected  DoublyLinkedNode<E> head
          Reference to head of the list.
protected  DoublyLinkedNode<E> tail
          Sign of the end of the list.
 
Constructor Summary
DoublyLinkedListIterator(DoublyLinkedNode<E> h)
          Construct an iterator over a doubly linked list hanging from head.
DoublyLinkedListIterator(DoublyLinkedNode<E> headDummy, DoublyLinkedNode<E> tailDummy)
           
 
Method Summary
 E get()
          Get reference to value that is current.
 boolean hasNext()
          Determine if there are more elements to be considered.
 E 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 structure5.AbstractIterator
hasMoreElements, iterator, nextElement, remove, value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

head

protected DoublyLinkedNode<E> head
Reference to head of the list.


tail

protected DoublyLinkedNode<E> tail
Sign of the end of the list.


current

protected DoublyLinkedNode<E> current
Reference to the current node in the list.

Constructor Detail

DoublyLinkedListIterator

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

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

DoublyLinkedListIterator

public DoublyLinkedListIterator(DoublyLinkedNode<E> headDummy,
                                DoublyLinkedNode<E> tailDummy)
Method Detail

reset

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

Specified by:
reset in class AbstractIterator<E>
Postcondition:
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<E>
Specified by:
hasNext in class AbstractIterator<E>
Returns:
True iff there are more elements to be considered.
See Also:
AbstractIterator.hasMoreElements()
Postcondition:
returns true iff current element is valid

next

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

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

get

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

Specified by:
get in class AbstractIterator<E>
Returns:
A reference to the value that is current.
Precondition:
hasNext
Postcondition:
returns current element