1 /**2 * @authorCody3 */4 Public classQuickSort {5 Public Static voidMain (string[] args) {6 int[] Array = {49,38,65,97,76,13,13,27,4,8,2,3,56};7QuickSort (array, 0, array.length-1);8 for(inti = 0; i < Array.Length; i++) {9 System.out.println (Array[i]);Ten } One } A - /** - * @paramnums array to be recursively processed the * @paramleft border begin 0 - * @paramright Border end length-1 - */ - Private Static voidQuickSort (int[] Nums,intLeftintRight ) { + intx = (left+right)/2; - intKey =Nums[x]; + inti =Left ; A intj =Right ; at intindex =x; - //If the length is one or out of bounds, no processing is required - if(left >= right)return; - while(I <j) { - //left to skip all >=key values - while(I < J && Nums[j] >=key) { inj--; - } to //on the right, skip all <key values. + while(I < J && Nums[i] <key) { -i++; the } * //use Index to save the array subscript where the key value is located $ //the corresponding value of x will not be changed or swapped oncePanax Notoginseng if(i = = x && i! =j) { -index =J; the } + if(j = = x && i! =j) { Aindex =i; the } + //exchange of the corresponding values of I and J - intTMP =Nums[i]; $Nums[i] =Nums[j]; $NUMS[J] =tmp; - } - //determine whether the value of i = = J (boundary) is greater or less than 0, divided into different places the if(Nums[i] <key) { -++i;Wuyi } the inttemp =Nums[i]; -Nums[i] =Nums[index]; WuNums[index] =temp; -QuickSort (nums,left,i-1); AboutQuickSort (nums,i+1, right); $ } -}
Fast-sorting Java implementation (key location can be taken)