ImportCn.idestiny.util.GeneratedArray;/*** @Auther: FAN * @Date: 2018/8/25 20:11 * @Description: Select sort each sort to select the smallest number to place in the corresponding position * 1) 3,5,1,2 min 1 and 3 swap * 2) 1,5,3,2 most Small value 2 and 5 Swap * 3) 1,2,3,5 sort complete **/ Public classSelectionsort { Public Static voidMain (string[] args) {int[] arr = Generatedarray.randomgeneratedarray (10, 50, 10000); LongStart =System.currenttimemillis (); Selectionsort (arr); System.out.println (System.currenttimemillis ()-start); //determine whether an array is orderedgeneratedarray.issorted (arr); } /*** Select sorting algorithm Implementation * *@paramarr*/ Public Static voidSelectionsort (int[] arr) { for(inti = 0; i < arr.length; i++) { //default Tag The current position element is the minimum value intMinindex =i; //loops through the current element is not the minimum value, if not, the replacement tag for(intj = i + 1; J < Arr.length; J + +) { if(Arr[minindex] >Arr[j]) {Minindex=J; } } //Swap element Location intTMP =Arr[i]; Arr[i]=Arr[minindex]; Arr[minindex]=tmp; } }}
Select sorting algorithm