© 1998-2002 McGraw-Hill

structure
Class DoublyLinkedListIterator

java.lang.Object
  |
  +--structure.AbstractIterator
        |
        +--structure.DoublyLinkedListIterator
All Implemented Interfaces:
Enumeration, Iterator

public class DoublyLinkedListIterator
extends AbstractIterator

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

Field Detail

head

protected DoublyLinkedListElement head
Reference to head of the list.

tail

protected DoublyLinkedListElement tail
Sign of the end of the list.

current

protected DoublyLinkedListElement current
Reference to the current node in the list.
Constructor Detail

DoublyLinkedListIterator

public DoublyLinkedListIterator(DoublyLinkedListElement h)
Construct an iterator over a doubly linked list hanging from head.
Parameters:
h - The head of the list to be traversed.

DoublyLinkedListIterator

public DoublyLinkedListIterator(DoublyLinkedListElement headDummy,
                                DoublyLinkedListElement tailDummy)
Method Detail

reset

public void reset()
Reset the iterator to the head of the list.
Overrides:
reset in class AbstractIterator
Postcondition:
resets iterator to list head

hasNext

public boolean hasNext()
Determine if there are more elements to be considered.
Overrides:
hasNext in class AbstractIterator
Postcondition:
returns true iff current element is valid
Returns:
True iff there are more elements to be considered.

next

public Object next()
Returns reference to the current element, then increments iterator.
Overrides:
next in class AbstractIterator
Postcondition:
returns current element and increments iterator
Returns:
Reference to element that was current before increment.

get

public Object get()
Get reference to value that is current.
Overrides:
get in class AbstractIterator
Precondition:
hasNext
Postcondition:
returns current element
Returns:
A reference to the value that is current.

© 1998-2002 McGraw-Hill