/** * * @authorAdministrator * Function: Select Sort Method*/ PackageCom.test1;ImportJava.util.Calendar; Public classSelectsort { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub//int[] arr = {1, 6, 0,-1, 9, -100, -90}; int[] arr =New int[50000]; for(inti = 0; i < arr.length; i++) { //let the program randomly produce a 1-10000 number//Math.random will produce a number from 0 to 1.Arr[i] = (int) (Math.random () *50000); }// //I think the first number is the smallest one .//int min = arr[0];// //Subscript for record minimum number//int minindex = 0;Select Select=NewSelect (); //Print the system time before sorting//Calendar is a single open mode, there is only one in the system, and only need an instance, not new out of the//Java 23 in total modeCalendar cal =calendar.getinstance (); System.out.println ("Before sorting:" +cal.gettime ()); Select.sort (arr); //Print the system time after sorting//because it is single-open, all the first to get the instance backCal =calendar.getinstance (); System.out.println ("After sorting:" +cal.gettime ());//System.out.println ("Select sort result is:");//for (int i = 0; i < arr.length; i++) {//System.out.print (arr[i]+ "");// } }}classselect{//Select Sort Public voidSortint[] arr) { for(inti = 0; i < arr.length; i++) { for(intj = i+1; J < Arr.length; J + +) { if(Arr[i] >Arr[j]) { inttemp =Arr[i]; Arr[i]=Arr[j]; ARR[J]=temp; } } } }}
Select Sort Selectsort