public class LinkedSimpleIterator implements SimpleIterator { Node current; Node previous; Node beforeprevious; LinkedSimpleCollection coll; public LinkedSimpleIterator (LinkedSimpleCollection coll) { current = coll.first; previous = null; beforeprevious = null; this.coll = coll; } public boolean hasNext() { return (current != null); } public E next() { if (current == null) { throw new java.util.NoSuchElementException(); } else { if (previous != null) beforeprevious = previous; previous = current; E n = current.element; current = current.next; return n; } } public void remove() { if (previous == null) throw new IllegalStateException(); else if (beforeprevious == null) coll.first = current; else beforeprevious.next = current; previous = null; } }