structure
Class CircularListIterator
java.lang.Object
|
+--structure.AbstractIterator
|
+--structure.CircularListIterator
- All Implemented Interfaces:
- Enumeration, Iterator
- class CircularListIterator
- extends AbstractIterator
An iterator for traversing the elements of a circular list.
The iterator traverses the list beginning at the head, and heads toward
tail.
Typical use:
List l = new CircularList();
// ...list gets built up...
Iterator li = l.iterator();
while (li.hasNext())
{
System.out.println(li.get());
li.next();
}
li.reset();
while (li.hasNext())
{ .... }
Method Summary |
Object |
get()
Determine the current value of iterator. |
boolean |
hasNext()
Determine if there are unconsidered elements. |
Object |
next()
Return the current value and increment iterator. |
void |
reset()
Resets iterator to consider the head of the list. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
tail
protected SinglyLinkedListElement tail
- The tail of the traversed list.
current
protected SinglyLinkedListElement current
- The current value of the iterator.
CircularListIterator
public CircularListIterator(SinglyLinkedListElement t)
- Constructs an iterator over circular list whose tail is t
- Parameters:
t
- The tail of the list to be traversed.
reset
public void reset()
- Resets iterator to consider the head of the list.
- Overrides:
reset
in class AbstractIterator
- Postcondition:
- rests iterator to point to head of list
hasNext
public boolean hasNext()
- Determine if there are unconsidered elements.
- Overrides:
hasNext
in class AbstractIterator
- Postcondition:
- returns true if some elements not visited
- Returns:
- True iff some element has not been considered.
next
public Object next()
- Return the current value and increment iterator.
- Overrides:
next
in class AbstractIterator
- Precondition:
- hasNext()
- Postcondition:
- returns current element, increments iterator
- Returns:
- The current value before incrementing.
get
public Object get()
- Determine the current value of iterator.
- Overrides:
get
in class AbstractIterator
- Precondition:
- hasNext()
- Postcondition:
- returns current value
- Returns:
- The current value of the iterator.