@Test public void testReverse() { linkedList.reverse(); Assert.assertEquals(3, linkedList.size()); Assert.assertEquals(Integer.valueOf(1), linkedList.remove()); Assert.assertEquals(2, linkedList.size()); Assert.assertEquals(Integer.valueOf(2), linkedList.remove()); Assert.assertEquals(1, linkedList.size()); Assert.assertEquals(Integer.valueOf(1), linkedList.remove()); Assert.assertEquals(0, linkedList.size()); }
public void reverse() { if (size <= 1) { return; } LinkedListNode<E> predecessor = head; LinkedListNode<E> current = head.successor(); LinkedListNode<E> successor = null; while (current != this.tail) { successor = current.successor(); current.setSuccessor(predecessor); predecessor = current; current = successor; } tail = head; tail.setSuccessor(null); head = current; head.setSuccessor(predecessor); }
LinkedList { public void reverse() { if (size <= 1) { return; } LinkedListNode<E> predecessor = head; LinkedListNode<E> current = head.successor(); LinkedListNode<E> successor = null; while (current != this.tail) { successor = current.successor(); current.setSuccessor(predecessor); predecessor = current; current = successor; } tail = head; tail.setSuccessor(null); head = current; head.setSuccessor(predecessor); } }
LinkedList { public void reverse() { if (size <= 1) { return; } LinkedListNode<E> predecessor = head; LinkedListNode<E> current = head.successor(); LinkedListNode<E> successor = null; while (current != this.tail) { successor = current.successor(); current.setSuccessor(predecessor); predecessor = current; current = successor; } tail = head; tail.setSuccessor(null); head = current; head.setSuccessor(predecessor); } LinkedList();  LinkedList(Collection<E> elements); }
LinkedList { public void reverse() { if (size <= 1) { return; } LinkedListNode<E> predecessor = head; LinkedListNode<E> current = head.successor(); LinkedListNode<E> successor = null; while (current != this.tail) { successor = current.successor(); current.setSuccessor(predecessor); predecessor = current; current = successor; } tail = head; tail.setSuccessor(null); head = current; head.setSuccessor(predecessor); } LinkedList();  LinkedList(Collection<E> elements); boolean add(E e); boolean add(int index, E e); boolean addAll(Collection<E> elements); E remove(); E remove(int index); E peek(); int size(); boolean isEmpty(); void reverse(); LinkedListNode<E> head(); LinkedListNode<E> tail(); E get(int index); void set(int index, E element); int indexOf(E element); int lastIndexOf(E element); @Override String toString(); }
LinkedList { public void reverse() { if (size <= 1) { return; } LinkedListNode<E> predecessor = head; LinkedListNode<E> current = head.successor(); LinkedListNode<E> successor = null; while (current != this.tail) { successor = current.successor(); current.setSuccessor(predecessor); predecessor = current; current = successor; } tail = head; tail.setSuccessor(null); head = current; head.setSuccessor(predecessor); } LinkedList();  LinkedList(Collection<E> elements); boolean add(E e); boolean add(int index, E e); boolean addAll(Collection<E> elements); E remove(); E remove(int index); E peek(); int size(); boolean isEmpty(); void reverse(); LinkedListNode<E> head(); LinkedListNode<E> tail(); E get(int index); void set(int index, E element); int indexOf(E element); int lastIndexOf(E element); @Override String toString();  }