Write it over again and forget it!
The fastest platoon
1 Public classFastsort {2 Public Static voidMain (string[] args)throwsexception{3 int[] A = {10, 1, 2, 3, 7, 3, 8, 5, 6, 4};4Fastsort B1 =NewFastsort ();5B1.sort (a,0,a.length-1);6 }7 voidSortint[] A,intLintRthrowsexception{8 inti,j,t,temp;9i =l;Tenj =R; Onetemp =A[l]; A if(l>S) { - return; - } the while(i!=j) { - while(I<j && a[j]>=temp) { -j--; - } + while(I<j && a[i]<=temp) { -i++; + } A if(i<j) { att =A[i]; -A[i] =A[j]; -A[J] =T; - } - } -A[L] =A[i]; inA[i] =temp; -System.out.print ("/"); to for(inth=0;h<a.length;h++){ +System.out.print (a[h]+ ""); - } theSort (A, L, i-1); *Sort (A, i+1, R); $ }Panax Notoginseng}
No.2 Bubble sort
1 Public classBubblesort {2 Public Static voidMain (String []args) {3 int[]a = {3,5,72,3,8,90};4 sort (a);5 }6 Public Static voidSortint[]a] {7 inttemp;8 for(inti = a.length-1; i > 0; i--){9 for(intj = 0; J < I; J + +){Ten if(A[j+1] <A[j]) { Onetemp = a[j+1]; AA[J+1] =A[j]; -A[J] =temp; - } the } - } - for(intk = 0; k<a.length;k++){ -System.out.print (a[k]+ ","); + } - } +}
No.3 Insert Sort
1 Public classInsertsort {2 Public Static voidMain (string[] args) {3 int[]a = {3,4,4,2,5,4,6,3,2};4 sort (a);5 }6 Static voidSortint[] a) {7 for(inti = 1; i < a.length; i++){8 for(intj = i; J > 0; j--){9 if(a[j]<a[j-1]){Ten inttemp =A[j]; OneA[J] = a[j-1]; AA[J-1] =temp; - } - } the } - for(intK = 0;k<a.length;k++) -System.out.print (a[k]+ ""); - } +}
Relive the classic sort Java implementation