Core idea:
each find max number,put it in unused postion
Introduce
loop : A
find a number i and i is max number in array. swap i and n. then n=n-1
repeat A until n ==0
Code
private static void selectSort(int[] a) {
for (int i = 0; i < a.length; i++) {
int minIndex = i;
for (int j = i + 1; j < a.length; j++) {
if (a[j] < a[minIndex]) {
minIndex = j;
}
}
if (minIndex != i) {
int tmp = a[minIndex];
a[minIndex] = a[i];
a[i] = tmp;
}
}
}