WiggleSort { public void wiggleSortN(int[] nums) { if (nums.length >= 2) { Arrays.sort(nums); boolean flag = true; int i = 1, j = nums.length - 1; while (i < j && nums[i] != nums[i + 1] && nums[j] != nums[j - 1]) { if (flag) { swap(nums, i, j); } i++; j--; flag = !flag; } } }  void wiggleSort(int[] nums); void wiggleSortN(int[] nums);  }
@Test(dataProvider = "wiggleSortArray") public void testWiggleSortN(int[] nums) { new WiggleSort().wiggleSortN(nums); assertTrue(String.format("%s is not wiggle sorted", IntStream.of(nums).mapToObj(String::valueOf). collect(joining(",", "[", "]"))), wiggleSortedN(nums)); }