|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.AbstractIterator | +--structure.SinglyLinkedListIterator
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()) { .... }
Field Summary | |
protected SinglyLinkedListElement |
current
The reference to currently considered element within list. |
protected SinglyLinkedListElement |
head
The head of list. |
Constructor Summary | |
SinglyLinkedListIterator(SinglyLinkedListElement t)
Construct an iterator that traverses list beginning at t. |
Method Summary | |
java.lang.Object |
get()
Return structure's current object reference. |
boolean |
hasNext()
Determine if the iteration is finished. |
java.lang.Object |
next()
Return current value and increment Iterator. |
void |
reset()
Reset iterator to beginning of the structure. |
Methods inherited from class structure.AbstractIterator |
hasMoreElements, nextElement, remove, value |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected SinglyLinkedListElement current
protected SinglyLinkedListElement head
Constructor Detail |
public SinglyLinkedListIterator(SinglyLinkedListElement t)
t
- The first element of list to be traversed.Method Detail |
public void reset()
reset
in class AbstractIterator
public boolean hasNext()
hasNext
in interface java.util.Iterator
hasNext
in class AbstractIterator
AbstractIterator.hasMoreElements()
public java.lang.Object next()
next
in interface java.util.Iterator
next
in class AbstractIterator
AbstractIterator.hasMoreElements()
,
AbstractIterator.value()
public java.lang.Object get()
get
in class AbstractIterator
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |