public class LinkedSimpleCollection implements SimpleCollection { Node first = null; public boolean add(E element) { Node newnode = new Node(element, first); first = newnode; return true; } public boolean contains(Object o) { for (Node current = first; current != null; current = current.next) { if ( (current.element == null && o == null) || current.element.equals(o)) { return true; } } return false; } public SimpleIterator iterator() { return new LinkedSimpleIterator(this); } public void rotate(){ if (first == null || first.next == null) return; Node f = first; first = first.next; Node curr = first; while (curr.next != null) curr = curr.next; curr.next = f; f.next = null; } public void reverse(){ Node current = first; first = null; while (current != null) { Node save = current; current = current.next; save.next = first; first = save; } } public void removeAll(E toRemove){ while(first != null && first.element.equals(toRemove)) first = first.next; if(first == null) return; Node current = first.next; Node previous = first; while(current != null){ if (current.element.equals(toRemove)) { if (previous == null) throw new IllegalStateException(); else previous.next = current.next; } else { previous = current; } current = current.next; } } }