structure
Class SinglyLinkedListIterator
java.lang.Object
|
+--structure.AbstractIterator
|
+--structure.SinglyLinkedListIterator
- All Implemented Interfaces:
- Enumeration, Iterator
- class SinglyLinkedListIterator
- extends AbstractIterator
An iterator for traversing the elements of a singly linked list.
The iterator traverses the list beginning at the head, and heads toward
tail.
Typical use:
List l = new SinglyLinkedList();
// ...list gets built up...
AbstractIterator li = l.iterator();
while (li.hasNext())
{
System.out.println(li.get());
li.next();
}
li.reset();
while (li.hasNext())
{ .... }
Method Summary |
Object |
get()
Return structure's current object reference. |
boolean |
hasNext()
Determine if the iteration is finished. |
Object |
next()
Return current value and increment Iterator. |
void |
reset()
Reset iterator to beginning of the structure. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
current
protected SinglyLinkedListElement current
- The reference to currently considered element within list.
head
protected SinglyLinkedListElement head
- The head of list.
SinglyLinkedListIterator
public SinglyLinkedListIterator(SinglyLinkedListElement t)
- Construct an iterator that traverses list beginning at t.
- Parameters:
t
- The first element of list to be traversed.
reset
public void reset()
- Reset iterator to beginning of the structure.
- Overrides:
reset
in class AbstractIterator
- Postcondition:
- iterator is reset to beginning of traversal
hasNext
public boolean hasNext()
- Determine if the iteration is finished.
- Overrides:
hasNext
in class AbstractIterator
- Postcondition:
- returns true if there is more structure to be viewed:
i.e., if value (next) can return a useful value.
- Returns:
- True if the iterator has more elements to be considered.
next
public Object next()
- Return current value and increment Iterator.
- Overrides:
next
in class AbstractIterator
- Precondition:
- traversal has more elements
- Postcondition:
- returns current value and increments iterator
- Returns:
- The current value, before increment.
get
public Object get()
- Return structure's current object reference.
- Overrides:
get
in class AbstractIterator
- Precondition:
- traversal has more elements
- Postcondition:
- returns current value referenced by iterator
- Returns:
- Object currently referenced.