C++ quick sort
作者:互联网
int Util::partition9(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++; swap(&arr[i],&arr[j]); } } swap(&arr[i + 1], &arr[high]); return i + 1; } void Util::quickSort10(int *arr,int low,int high) { if(low<high) { int pivot=partition9(arr,low,high); quickSort10(arr,low,pivot-1); quickSort10(arr,pivot+1,high); } } void Util::array11(int len) { int *arr=new int[len]; getArray(arr,len); cout<<"Print array before quick sort:"<<endl; printArray(arr,len); cout<<"Print array after quick sort:"<<endl; quickSort10(arr,0,len-1); printArray(arr,len); cout<<"Finished in void Util::array(int len) and now is "<<getTimeNow()<<endl; } void array4(int len = 100); int main() { array4(100); return 0; } void array4(int len) { Util ul; ul.array11(len); }
标签:sort,Util,arr,int,C++,high,++,low,quick 来源: https://www.cnblogs.com/Fred1987/p/15942219.html