1 Public classQuickrank {2 Public Static voidMain (string[] args) {3 int[] original={26,58,1,24,75,69,32,45,841,25898};4Quickrank quickrank=NewQuickrank ();5Quickrank.ranksimple (original,0,original.length-1);6 for(inti:original)7 System.out.println (i);8 }9 //clearly understoodTen Public voidRanksimple (int[] Original,intStartintend) { One if(End<=start)return;//Recursive End Condition A intstandard=Original[start]; - intLeftorder=start; - intRightorder=end; the while(leftorder<Rightorder) { - //run from right to left - while(Leftorder<rightorder && original[rightorder]>Standard ) -rightorder--; +original[leftorder]=Original[rightorder]; - //run from left to right + while(Leftorder<rightorder && original[leftorder]<Standard ) Aleftorder++; atoriginal[rightorder]=Original[leftorder]; - } -original[leftorder]=Standard ; - //Recursive start -Ranksimple (original, Start, leftOrder-1); -Ranksimple (Original, leftorder+1, end); in } -}
results:12426324558697584125898
The idea of a fast sorting algorithm:
1. Once sorted (before sorting ends, there is always a position in the array as "null", where the data is to be inserted):
① a value for the sorted array (this example takes the first value) as the benchmark value for this order, the original array is considered null, and is to be inserted.
② from the array to the left, compares each value to the size of the Standar, and, if there is less than standard, inserts the value into the empty range in the array, where the value is treated as a null value in the array.
③ the array from left to right, compares each value to the Standar size, and then inserts the value into the empty range in the array if it is larger than the standard, at which point the value in the array is treated as a null value.
④ Loop The ②③ step until the ordinal is equal from right to left and left to right, indicating that the order is finished and the standard is placed in the ordinal position. At this point, all the numbers before the sequence number are less than standard, after the number of all numbers are greater than standard, forming two small array;
2. Iteration
After a sort step, we get the standard before and after two arrays, then the two arrays are sorted once, and iterative;
3. Iteration End Flag:
The beginning and ending positions of the array entering a sort are equal, that is, a number is passed in, no sorting is required;
Java implementation of fast sorting algorithm