1 /*2 Quick sort of getting started3 complexity of Time: O (NLOGN)4 The worst case time complexity can reach O (n^2)5 An introduction to self-algorithmic learning6 */7#include <iostream>8 using namespacestd;9 intA[] = {3,7,8,5,4,6,2,1,3};Ten voidQuick_sort (int*,int,int); One voidSwapint,int); A voidprint (); - intMain () - { thePrint ();//before sorting -Quick_sort (A,0,8); -Print ();//after sorting - } + voidprint () - { + for(intI=0; a[i]!=0; ++i) Acout << A[i] <<" "; atcout <<Endl; - } - voidSwapintXinty) - { - intt =A[x]; -A[X] =A[y]; inA[y] =T; - } to voidQuick_sort (intA[],intLintR//separate the <t and the >=t + { - if(L >=R) the return ; * intt = A[r],j = L1;//Boundary Problems $ for(intI=l; i<r; ++i)Panax Notoginseng if(A[i] <t) - { the++J; + if(I! =j) A swap (I,J); the } +Swap (j+1, R); - Quick_sort (a,l,j); $Quick_sort (a,j+2, R); $}
Quick sort of getting started