Quick sorting is the most classic sorting. The idea is to select a benchmark value, usually the first. Then, all values are compared with the reference values, and the positions in the larger values remain unchanged,
The small position is exchanged with the first large position. In this way, the first round of sorting is performed, and the two sides of the benchmark value are then sorted, and so on until there is one left.
The following is the code for the quick release:
Public class quicksort {public void quicksort (int A [], int start, int end) {// compare whether only one value of this array is not sorted quickly if (start <End) {// reference value: int keyword = A [start]; int I = start; For (Int J = I + 1; j <= end; j ++) {// compare with the reference value, the large position remains the same, and the small one exchanges with the first large if (a [J] <keyword) {int temp = A [J]; A [J] = A [I + 1]; A [I + 1] = temp; I ++;} A [start] = A [I]; A [I] = keyword; // and so on, recursively sort all the quicksort (A, start, I-1); quicksort (A, I + 1, end) ;}} public static void main (string [] ARGs) {random = new random (); int [] A = new int [10000]; for (INT I = 0; I <. length; I ++) {A [I] = random. nextint (10000);} Long starttime = system. currenttimemillis (); quicksort = new quicksort (); quicksort. quicksort (A, 0,. length-1); long endtime = system. currenttimemillis (); system. out. println ("program running time:" + (endtime-starttime) + "Ms"); // The sorted sequence system. out. println ("sorted sequence:"); For (INT I = 0; I <. length; I ++) {system. out. println (A [I]) ;}}
The code is very simple.
Quick sorting of classic sorting