Require: Array arr[] to sort by selection sort.
Ideas:
1, starting with the first element (the corner mark is 0), and comparing each element behind it, the smaller number is stored in the first element, so that the first element is the smallest value.
2, starting with the second element, and comparing it with each element behind it, the smaller number is stored in the second element, so that the second element is the smallest value except the first one.
3, continue ....
4, the second-to-last element (the corner mark is length-2), and the second-to-last element (length-1), the smaller one in the penultimate element.
At this point, the sorting is complete.
Implementation code:
Select sort
public static void Xuanze (int[] a) {
for (int i=0;i<a.length-1;i++) {//Select the number in the array
for (int j=i+1;j<a.length;j++) {//Select and array all to compare sort
if (A[i]>a[j]) {
int temp=a[i];
A[I]=A[J];
A[j]=temp;
}
}
}
}
Sorting of arrays in Java, selecting Sort method