package plp.collection; import java.util.Iterator; import java.util.NoSuchElementException; public class CListIterator implements Iterator { private final CList clist; private Cell current; public CListIterator(CList clist) { this.clist = clist; current = clist.first().next(); } public boolean hasNext() { return current != clist.end(); } public Object next() { if (! hasNext()) { throw new NoSuchElementException(); } Object o = current.data(); current = current.next(); return o; } /** remove() is not possible during iteration in a CList. */ public void remove() { throw new UnsupportedOperationException(); } }