@Test public void testEvenOddMerge() { LinkedList<Integer> l = newLinkedList(1, 2, 3, 4, 5); evenOddMerge(l); LinkedListNode<Integer> runningNode = l.head(); int[] merged = new int[] { 1, 3, 5, 2, 4 }; assertArrayEqualsList(merged, runningNode); l = newLinkedList(1, 2, 3, 4, 5, 6); evenOddMerge(l); runningNode = l.head(); merged = new int[] { 1, 3, 5, 2, 4, 6 }; assertArrayEqualsList(merged, runningNode); }
public static void evenOddMerge(LinkedList<Integer> l) { LinkedListNode<Integer> evenPointer = l.head(); LinkedListNode<Integer> oddPointer = l.head(); LinkedListNode<Integer> oddHead = null; while (evenPointer.successor() != l.tail()) { oddPointer = evenPointer.successor().successor(); LOGGER.info("Odd pointer is at: {}.", oddPointer); if (oddHead == null) { oddHead = oddPointer; } evenPointer = evenPointer.successor(); LOGGER.info("Even pointer is at: {}.", evenPointer); if (oddPointer.successor() != null) { LOGGER.info("Setting even pointer successor to: {}.", oddPointer.successor()); evenPointer.setSuccessor(oddPointer.successor()); } if (evenPointer.successor() != l.tail()) { LOGGER.info("Setting odd pointer successor to: {}.", evenPointer.successor()); oddPointer.setSuccessor(evenPointer.successor().successor()); } } evenPointer.setSuccessor(oddHead); }
PracticeQuestionsCh7 { public static void evenOddMerge(LinkedList<Integer> l) { LinkedListNode<Integer> evenPointer = l.head(); LinkedListNode<Integer> oddPointer = l.head(); LinkedListNode<Integer> oddHead = null; while (evenPointer.successor() != l.tail()) { oddPointer = evenPointer.successor().successor(); LOGGER.info("Odd pointer is at: {}.", oddPointer); if (oddHead == null) { oddHead = oddPointer; } evenPointer = evenPointer.successor(); LOGGER.info("Even pointer is at: {}.", evenPointer); if (oddPointer.successor() != null) { LOGGER.info("Setting even pointer successor to: {}.", oddPointer.successor()); evenPointer.setSuccessor(oddPointer.successor()); } if (evenPointer.successor() != l.tail()) { LOGGER.info("Setting odd pointer successor to: {}.", evenPointer.successor()); oddPointer.setSuccessor(evenPointer.successor().successor()); } } evenPointer.setSuccessor(oddHead); } }
PracticeQuestionsCh7 { public static void evenOddMerge(LinkedList<Integer> l) { LinkedListNode<Integer> evenPointer = l.head(); LinkedListNode<Integer> oddPointer = l.head(); LinkedListNode<Integer> oddHead = null; while (evenPointer.successor() != l.tail()) { oddPointer = evenPointer.successor().successor(); LOGGER.info("Odd pointer is at: {}.", oddPointer); if (oddHead == null) { oddHead = oddPointer; } evenPointer = evenPointer.successor(); LOGGER.info("Even pointer is at: {}.", evenPointer); if (oddPointer.successor() != null) { LOGGER.info("Setting even pointer successor to: {}.", oddPointer.successor()); evenPointer.setSuccessor(oddPointer.successor()); } if (evenPointer.successor() != l.tail()) { LOGGER.info("Setting odd pointer successor to: {}.", evenPointer.successor()); oddPointer.setSuccessor(evenPointer.successor().successor()); } } evenPointer.setSuccessor(oddHead); }  }
PracticeQuestionsCh7 { public static void evenOddMerge(LinkedList<Integer> l) { LinkedListNode<Integer> evenPointer = l.head(); LinkedListNode<Integer> oddPointer = l.head(); LinkedListNode<Integer> oddHead = null; while (evenPointer.successor() != l.tail()) { oddPointer = evenPointer.successor().successor(); LOGGER.info("Odd pointer is at: {}.", oddPointer); if (oddHead == null) { oddHead = oddPointer; } evenPointer = evenPointer.successor(); LOGGER.info("Even pointer is at: {}.", evenPointer); if (oddPointer.successor() != null) { LOGGER.info("Setting even pointer successor to: {}.", oddPointer.successor()); evenPointer.setSuccessor(oddPointer.successor()); } if (evenPointer.successor() != l.tail()) { LOGGER.info("Setting odd pointer successor to: {}.", evenPointer.successor()); oddPointer.setSuccessor(evenPointer.successor().successor()); } } evenPointer.setSuccessor(oddHead); }  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 evenOddMerge(LinkedList<Integer> l) { LinkedListNode<Integer> evenPointer = l.head(); LinkedListNode<Integer> oddPointer = l.head(); LinkedListNode<Integer> oddHead = null; while (evenPointer.successor() != l.tail()) { oddPointer = evenPointer.successor().successor(); LOGGER.info("Odd pointer is at: {}.", oddPointer); if (oddHead == null) { oddHead = oddPointer; } evenPointer = evenPointer.successor(); LOGGER.info("Even pointer is at: {}.", evenPointer); if (oddPointer.successor() != null) { LOGGER.info("Setting even pointer successor to: {}.", oddPointer.successor()); evenPointer.setSuccessor(oddPointer.successor()); } if (evenPointer.successor() != l.tail()) { LOGGER.info("Setting odd pointer successor to: {}.", evenPointer.successor()); oddPointer.setSuccessor(evenPointer.successor().successor()); } } evenPointer.setSuccessor(oddHead); }  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; }