1#include <stdlib.h>2#include <stdio.h>3 4 #defineArray_size 105 6 voidSwapint*x,int*y)7 {8 intA = *x;9*x = *y;Ten*y =A; One } A - intRandint (intLowintHigh ) - { the return(Low + (rand ()% (high-low +1))); - } - - voidQuicksortint*arr,intLowintHigh ) + { - intI, Mid; + if(Low >=High ) A return; atSwap (Arr+low, arr +randint (Low, High)); -MID =Low ; - for(i = low+1; I <= high; i++) - { - if(Arr[i] <Arr[low]) - { inSwap (arr + ++mid, arr +i); - } to } +Swap (arr + low, arr +mid); -Quicksort (arr, Low, mid-1); theQuicksort (arr, mid+1, high); * } $ Panax Notoginseng voidPrintArray (int*arr,intSizeConst Char*prefix) - { theprintf"%s:", prefix); + for(inti =0; I < size-1; i++) A { theprintf"%d", Arr[i]); + } -printf"\ n"); $ } $ - intMainintargcChar**argv) - { the intArray_unsort[array_size] = { One, at, -, -, +, A,8,9, the, the}; -PrintArray (Array_unsort, Array_size,"before sort");WuyiQuicksort (Array_unsort,0, array_size-1); thePrintArray (Array_unsort, Array_size,"After sort"); - return 0; Wu -}
Implementation method of Quick Sort quicksort