#include <string>#include<vector>#include<fstream>using namespaceStd;std::vector<int>v;intbigarr[10000];inthelparr[10000];intPartitionint* Arr,intLeftintRight );intQSort (int* Arr,intLeftintRight ) { if(Left >=Right ) { return 0; } intPartionidx =partition (arr, left, right); intLeftcmpnum = QSort (Arr,left, Partionidx-1 ); intRightcmpnum = QSort (arr, Partionidx +1, right); return(right-left) + Leftcmpnum +Rightcmpnum;}intPartitionint* Arr,intLeftintRight ) { if(Left >=Right ) { returnLeft ; } intKey =Arr[left]; intLastlessidx =Left ; intIDX = left +1; while(IDX <=Right ) { if(Arr[idx] <key) { intTMP =Arr[idx]; Lastlessidx++; ARR[IDX]=Arr[lastlessidx]; ARR[LASTLESSIDX]=tmp; } idx++; } intTMP =Arr[lastlessidx]; ARR[LASTLESSIDX]=Arr[left]; Arr[left]=tmp; returnLastlessidx;}voidMain () {FStream infile ("QuickSort.txt" ); stringtmp; while(Getline (infile, tmp)) {intnum =atoi (Tmp.c_str ()); V.push_back (num); } for(inti =0; I <10000; i++) {Bigarr[i]=v.at (i); } intCmpnum = QSort (Bigarr,0,9999 );}
Algorithms:design and analysis, Part 1 "Program 2/Statistics Fast comparison"