Quick Sort algorithm:
//QuickSort.cpp: Defines the entry point of the console application. //#include<iostream>using namespacestd;template<typename t>voidQSort (t* A,intN) { if(N <=1)//Remember that is less than or equal to 1 { return; } if(n = =2) { if(a[0] > a[1]) Swap (a[0], a[1]); return;//I remember a return .} swap (*a, a[n>>1]); T v= *A; T* L = a +1; T* R = a + N-1; while(L <R) { while(*l < v && L < R) l++;//remember is less than, to wait until > while(*r > v && R > a) r--;//remember it was r-- . if(L <R) Swap (*l, *s); } Swap (a[0], *s); QSort (A, R-a);//remember, starting with a .QSort (R +1N1-(r-a));//Remember the total number of calculation methods minus the cutoff value minus the number of left}intMainintargcChar*argv[]) { inta[Ten]; for(inti =0; I <Ten; ++i) a[i]=Ten-i; QSort (A,Ten); for(inti =0; I <Ten; ++i) cout<< A[i] <<"" ; cout<<Endl; return 0;}
Quick Sort Code Backup