C++ quick sort
//Util.cpp void Util::arrayQuickSort8(int len) { int *arr=new int[len]; getArray(arr,len); cout<<"Before quick sort:"<<endl; printArray(arr,len); cout<<"After quick sort:"<<endl; quickSortAsc7(arr,0,len-1); printArray(arr,len); delete[] arr; cout<<getTimeNow()<<",finished in void Util::arrayQuickSort8(int len)!"<<endl; } void Util::quickSortAsc7(int *arr,int low,int high) { if(low<high) { int pivot=partitionAsc6(arr,low,high); quickSortAsc7(arr,low,pivot-1); quickSortAsc7(arr,pivot+1,high); } } int Util::partitionAsc6(int *arr,int low,int high) { int pivot=arr[high]; int i=low-1; for(int j=low;j<high;j++) { if(arr[j]<pivot) { i=i+1; swap(&arr[i],&arr[j]); } } swap(&arr[i+1],&arr[high]); return i+1; } void Util::swap(int *left,int *right) { int temp=*left; *left=*right; *right=temp; } void Util::printArray(int *arr,int len) { for(int i=0;i<len;i++) { cout<<arr[i]<<"\t"; } cout<<endl<<endl; } void Util::getArray(int *arr,int len) { srand(time(NULL)); for(int i=0;i<len;i++) { arr[i]=rand(); } } //main.cpp void arrayQuickSort(int len); int main(int args,char **argv) { arrayQuickSort(atoi(argv[1])); } void arrayQuickSort(int len) { Util ul; ul.arrayQuickSort8(len); }
g++ -std=c++2a -I. *.cpp ./Model/*.cpp -o h1 -luuid -lpthread;