@Test public void descendingOrderSort() { int[] array = { 1, 2, 3, 4, 5 }; int[] sorted = StupidSort.stupidSort(array, descOrderComparator); assertArrayEquals("Failure => Array returned is not sorted.", sorted, new int[] { 5, 4, 3, 2, 1 }); }
public static int[] stupidSort(int[] array, Comparator<Integer> comparator) { for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (comparator.compare(array[i], array[j]) > 0) { swap(array, i, j); } } } return array; }
StupidSort { public static int[] stupidSort(int[] array, Comparator<Integer> comparator) { for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (comparator.compare(array[i], array[j]) > 0) { swap(array, i, j); } } } return array; } }
StupidSort { public static int[] stupidSort(int[] array, Comparator<Integer> comparator) { for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (comparator.compare(array[i], array[j]) > 0) { swap(array, i, j); } } } return array; }  }
StupidSort { public static int[] stupidSort(int[] array, Comparator<Integer> comparator) { for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (comparator.compare(array[i], array[j]) > 0) { swap(array, i, j); } } } return array; }  static void swap(int[] array, int foo, int bar); static int[] stupidSort(int[] array, Comparator<Integer> comparator); }
StupidSort { public static int[] stupidSort(int[] array, Comparator<Integer> comparator) { for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (comparator.compare(array[i], array[j]) > 0) { swap(array, i, j); } } } return array; }  static void swap(int[] array, int foo, int bar); static int[] stupidSort(int[] array, Comparator<Integer> comparator);  }