@Test public void testReverse() { LinkedList<Integer> l = newLinkedList(1, 2, 3, 4, 5); reverse(l); LinkedListNode<Integer> runningNode = l.head(); int[] reversed = new int[] { 5, 4, 3, 2, 1 }; assertArrayEqualsList(reversed, runningNode); }
public static void reverse(LinkedList<Integer> l) { LinkedListNode<Integer> previous = l.head(); LinkedListNode<Integer> current = previous.successor(); LinkedListNode<Integer> next = current.successor(); while (next != l.tail()) { LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = current; current = next; next = next.successor(); } LOGGER.info("Swapping head and tail."); LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = l.head().successor(); l.head().setSuccessor(current); next.setSuccessor(previous); }
PracticeQuestionsCh7 { public static void reverse(LinkedList<Integer> l) { LinkedListNode<Integer> previous = l.head(); LinkedListNode<Integer> current = previous.successor(); LinkedListNode<Integer> next = current.successor(); while (next != l.tail()) { LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = current; current = next; next = next.successor(); } LOGGER.info("Swapping head and tail."); LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = l.head().successor(); l.head().setSuccessor(current); next.setSuccessor(previous); } }
PracticeQuestionsCh7 { public static void reverse(LinkedList<Integer> l) { LinkedListNode<Integer> previous = l.head(); LinkedListNode<Integer> current = previous.successor(); LinkedListNode<Integer> next = current.successor(); while (next != l.tail()) { LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = current; current = next; next = next.successor(); } LOGGER.info("Swapping head and tail."); LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = l.head().successor(); l.head().setSuccessor(current); next.setSuccessor(previous); }  }
PracticeQuestionsCh7 { public static void reverse(LinkedList<Integer> l) { LinkedListNode<Integer> previous = l.head(); LinkedListNode<Integer> current = previous.successor(); LinkedListNode<Integer> next = current.successor(); while (next != l.tail()) { LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = current; current = next; next = next.successor(); } LOGGER.info("Swapping head and tail."); LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = l.head().successor(); l.head().setSuccessor(current); next.setSuccessor(previous); }  static LinkedListNode<Integer> mergeLists(LinkedList<Integer> l, LinkedList<Integer> f); static LinkedListNode<Integer> startOfLoop(LinkedList<Integer> l); static LinkedListNode<Integer> intersection(LinkedList<Integer> l1, LinkedList<Integer> l2); static void evenOddMerge(LinkedList<Integer> l); static void reverse(LinkedList<Integer> l); }
PracticeQuestionsCh7 { public static void reverse(LinkedList<Integer> l) { LinkedListNode<Integer> previous = l.head(); LinkedListNode<Integer> current = previous.successor(); LinkedListNode<Integer> next = current.successor(); while (next != l.tail()) { LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = current; current = next; next = next.successor(); } LOGGER.info("Swapping head and tail."); LOGGER.info("Previous: {}, current: {}, next: {}.", previous, current, next); current.setSuccessor(previous); previous = l.head().successor(); l.head().setSuccessor(current); next.setSuccessor(previous); }  static LinkedListNode<Integer> mergeLists(LinkedList<Integer> l, LinkedList<Integer> f); static LinkedListNode<Integer> startOfLoop(LinkedList<Integer> l); static LinkedListNode<Integer> intersection(LinkedList<Integer> l1, LinkedList<Integer> l2); static void evenOddMerge(LinkedList<Integer> l); static void reverse(LinkedList<Integer> l); static final Logger LOGGER; }