OddEvenLinkedList { public static <T> ListNode<T> oddEvenList(ListNode<T> head) { if (head == null || head.next == null) return head; ListNode<T> prev = head, tail = head.next; ListNode<T> current = tail.next; while (current != null) { ListNode<T> currentNext = current.next; current.next = prev.next; prev.next = current; tail.next = currentNext; prev = prev.next; if (currentNext != null) { current = currentNext.next; } else { current = null; } tail = tail.next; } return head; }  static ListNode<T> oddEvenList(ListNode<T> head);  }
@Test(dataProvider = "oddEvenList") public void test(ListNode<Integer> original, List<Integer> expected) { TestUtilities.assertLinkedListValues(OddEvenLinkedList.oddEvenList(original), expected); }