首先,上图。
‘’’
```cpp
int partSort(int *a ,int left,int right)
{int keyi = left; //做左侧基准while(left<right){while(left<right && a[right]>=a[keyi]){right--;}while(left<right && a[left]<=a[keyi]){++left;}swap(a[left],a[right]);}//找到基准的位置swap(&a[left],&a[right]);//返回基准的位置方便以后用return left;
}
//递归void QuickSort(int* a,int left,int right)
{if(left<right){int pivot = partSort(a,left,right);QuickSort(a,left,pivot-1);QuickSort(a,pivot+1,right);}
}