1, the algorithm think
In the implementation of the selection of sorting, the first part of the entire record sequence is divided into ordered and unordered areas, the initial state ordered area is empty, the unordered area contains all the records to be sorted; the second pair of disordered regions, the record with the smallest key code is exchanged with the first record in the unordered area, and it is repeated to the disordered Area.
2. Algorithm implementation
Package test; public class Selectsort {public static void main (string[] Args) { int[] n ={1,3,6,2,9,6,8,7}; Selectsort (n); For (int i:n) { System.out.print (i+ "\ t");} } public static void Selectsort (int[] arr) {for (int i = 0;i<arr.length;i++) { int min = i; for (int j = I+1;j<arr.length;j++) { if (arr[min]>arr[j]) { min = j; } } If (i!=min) { int temp = arr[min]; arr[min]=arr[i]; arr[i]=temp;}}}}
Select Sort (ascending)