1 Packagesorting;2 3 /**4 * Quick Sort5 * Average O (nlogn), preferably O (nlogn), Worst O (n^2), Space complexity O (NLOGN), unstable, more complex6 * @authorZeng7 *8 */9 Public classKuaisupaixu {Ten One Public Static intSortint[] A,intIintj) { A intKey =A[i]; - while(I <j) { - while(I < J && A[j] >=key) thej--; -A[i] =A[j]; - while(I < J && A[i] <=key) -i++; +A[J] =A[i]; - } +A[i] =key; A returni; at } - - Public Static voidQuicksortint[] B,intLowintHigh ) { - - if(Low <High ) { - intPivotloc =sort (b, low, high); inSystem.out.println ("pivotloc=" +pivotloc); - for(inti:b) toSystem.out.print (i + "")); + System.out.println (); -Quicksort (b, Low, pivotloc-1); theQuicksort (b, Pivotloc + 1, high); * } $ Panax Notoginseng } - the Public Static voidMain (string[] args) { + int[] B = {49, 38, 65, 97, 76, 13, 27, 50 }; AQuicksort (b, 0, b.length-1); the + } -}
Sorting algorithm Java implementation (Quick Sort)