The basic idea of the fast sorting algorithm is to divide the pending records into two separate parts through a sort of sequencing, and some of the key words of the records are smaller than those of the other records, then the two parts of the records can be sorted separately to achieve the order of the whole sequence.
classpartitionsort{ Public voidPint[] a) {//PrintOut results for(inti=0;i<a.length;i++) {System.out.print (A[i]+" "); } System.out.println (); } Public intPartition (int[] A,intLowintHigh ) {//Find the ordinal of the middle position and returninttemp = A[low];//set The low number is middle number while(low<High ) { while(Low//This is the can not lost =,else are die loophigh--;//High position-1} A[low]=a[high];//< Middle number, make it in front of middle number while(lowA[low]) { Low++; } A[high]=A[low]; } A[low]=temp; returnLow ; } Public voidQSort (int[] A,intLowintHigh) {//Recurrence method to come true using recursive methods to sort if(a.length>0){ if(low<High ) { intPartition =Partition (A,low,high); QSort (A,low,partition-1); QSort (A,partition+1, high); } } } Public Static voidMain (String args[]) {int[] A = {38,49,65,97,76,13,27,49}; Partitionsort P=NewPartitionsort (); P.qsort (A,0,a.length-1); P.P (a); }}
Fast sort algorithm (Java)