选择排序
public static void main(String[] args) {
int[] a = {1, 4, 6, 2, 15, 24, 67, 45, 23, 99, 12, 8};
selectSort(a);
System.out.println(Arrays.toString(a));
}
public static void selectSort(int[] a) {
int size = a.length;
for (int i = 0; i < size - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < size; j++) {
if (a[j] < a[minIndex]) {
minIndex = j;
}
}
int tmp = a[i];
a[i] = a[minIndex];
a[minIndex] = tmp;
}
}
缘于生活,而归于工作。本人所书,而意于分享。
如有转载,请注明出处!
--活出自己范儿

浙公网安备 33010602011771号