@Test public void mysort() { Integer[] sortIntegerArray = {7,6,5,4,3}; Integer[] resultArray = {3,4,5,6,7}; SelectSort.mysort(sortIntegerArray); Assert.assertArrayEquals(sortIntegerArray, resultArray); }
public static void mysort(Comparable[] a) { for (int i = 0; i < a.length; i++) { int smallestIndex = i; for (int j = i + 1; j < a.length; j++) { if (Utils.less(a[j], a[smallestIndex])) { smallestIndex = j; } } if (Utils.less(a[smallestIndex], a[i])) { Utils.exch(a, smallestIndex, i); } } }
SelectSort { public static void mysort(Comparable[] a) { for (int i = 0; i < a.length; i++) { int smallestIndex = i; for (int j = i + 1; j < a.length; j++) { if (Utils.less(a[j], a[smallestIndex])) { smallestIndex = j; } } if (Utils.less(a[smallestIndex], a[i])) { Utils.exch(a, smallestIndex, i); } } } }
SelectSort { public static void mysort(Comparable[] a) { for (int i = 0; i < a.length; i++) { int smallestIndex = i; for (int j = i + 1; j < a.length; j++) { if (Utils.less(a[j], a[smallestIndex])) { smallestIndex = j; } } if (Utils.less(a[smallestIndex], a[i])) { Utils.exch(a, smallestIndex, i); } } } private  SelectSort(); }
SelectSort { public static void mysort(Comparable[] a) { for (int i = 0; i < a.length; i++) { int smallestIndex = i; for (int j = i + 1; j < a.length; j++) { if (Utils.less(a[j], a[smallestIndex])) { smallestIndex = j; } } if (Utils.less(a[smallestIndex], a[i])) { Utils.exch(a, smallestIndex, i); } } } private  SelectSort(); static void mysort(Comparable[] a); static void sort(Comparable[] a); static void sort(Object[] a, Comparator c); }
SelectSort { public static void mysort(Comparable[] a) { for (int i = 0; i < a.length; i++) { int smallestIndex = i; for (int j = i + 1; j < a.length; j++) { if (Utils.less(a[j], a[smallestIndex])) { smallestIndex = j; } } if (Utils.less(a[smallestIndex], a[i])) { Utils.exch(a, smallestIndex, i); } } } private  SelectSort(); static void mysort(Comparable[] a); static void sort(Comparable[] a); static void sort(Object[] a, Comparator c);  }