-
选择排序
`public class SelectSort {public static void main(String[] args) {
int[] eles = {0, -1, -3, 2, 100, Integer.MAX_VALUE, Integer.MIN_VALUE};
selectSort(eles);
System.out.println(Arrays.toString(eles));
}
public static void selectSort(int[] eles) {
int minIdx = 0;
for (int i = 0; i < eles.length; i++) {
int min = eles[i];
for (int j = i + 1; j < eles.length; j++) {
if (min > eles[j]) {
min = eles[j];
minIdx = j;
}
}
swap(eles, i, minIdx);
}
}private static void swap(int [] eles, int idx1, int idx2) {
int tmp = eles[idx1];
eles[idx1] = eles[idx2];
eles[idx2] = tmp;
}
}`