int Partition(int a[], int low, int high) { int pivot = a[low]; while(low < high) { while(low < high && a[high] >= pivot) high--; a[low] = a[high]; // 将比枢轴值小的的元素移动到左端 while(low < high && a[low] <= pivot) low++; a[high] = a[low]; } a[low] = pivot; return low; }
void quickSort(int a[], int low, int high) {
if(low < high) { int pivotpos = Partition(a, low, high); quickSort(a, low, pivotpos -1); quickSort(a, pivotpos+1, high); } }
转载请注明原文地址: https://ju.6miu.com/read-3252.html