1#include <iostream>2 using namespacestd;3#include <stdlib.h>4 5 #defineLEN 126 7 intQuickSort (int*arr,intStartintend);8 intSort (int*arr,intStartintend);9 intSwapint&a,int&b);Ten One intMain () A { -Srand -); - intA[len] = { -, +,9,5, A,8,7,4, +,2,6, One}; theQuickSort (A,0, One); - for(inti =0; I < len;i++) - { -cout<<a[i]<<Endl; + } - } + A intQuickSort (int*arr,intStartintend) at { - if(Start <end) - { - inti = Sort (arr,start,end);//divide the position of the principal I into two arrays -QuickSort (Arr,start,i-1); -QuickSort (Arr,i +1, end); in } - return 0; to } + - intSort (int*arr,intStartintend) the { * intPIV = rand ()% (end +1-start) + start;//random selection of the main element $ swap (arr[piv],arr[end]);Panax Notoginseng //the range of the i-j is a value smaller than the primary, and the range of the j-end is larger than the main element - inti = Start-1; the + for(intK = start; K < end; k++) A { the if(Arr[k] <=Arr[end]) + { -i = i+1; $ swap (arr[i],arr[k]); $ } - } -Swap (arr[i+1],arr[end]); the returni+1; - }Wuyi the intSwapint&a,int&b) - { Wu inttmp; -TMP =A; AboutA =b; $b =tmp; - return 0; -}
Quick ordering of the main elements is selected