Choosing a sort (select sorting) is also a simple sort method. Its basic ideas are:
First select the minimum value from r[0]-r[n1], swap with r[0],
The second time from r[1]-r[n-1] to select the minimum value, and r[1] exchange,
The third time from r[2]-r[n-1] to choose the minimum value, and r[2] exchange, ...,
I select the minimum value from r[i-1]-r[n-1], swap with r[i-1], ...,
Section n-1 from r[n-2]-r[n-1] to select the minimum value, and r[n-2] exchange, a total of n-1 times, to get a sort code from small to large order sequence.
Packagesorting; Public classsecectionsorting {//Select Sort Public Static voidMain (string[] args) {//TODO auto-generated Method Stub intarr[]={2,5,11,23,14,12,20,17}; intTemp=0; for(inti=0;i<arr.length-1;i++){ //Suppose the first one is the smallest number intmin=Arr[i]; //record the smallest subscript intminindex=i; for(intk=i+1;k<arr.length;k++){ if(min>Arr[k]) { //Modify Minimum Valuemin=Arr[k]; Minindex=K; } } //This minimum value is found when the outer for loop is introduced.temp=Arr[i]; Arr[i]=Arr[minindex]; Arr[minindex]=temp; } //The Foreach method iterates through the sorting results of the output array a for(intE:arr) {System.out.print (e+ "<"); } }}
Java selection Sort