快排partition函数
int partition(int p,int r) {
int low,high;
low=p;
high=r;
int temp;
temp=a[low];
while(low<high) {
while(low<high&&a[high]>=temp) //从后面扫描
high--;
a[low]=a[high];
while(low<high&&a[low]<=temp)//从前面扫描
low++;
a[high]=a[low];
}
a[low]=temp;//最后将基准填入移完的空内
return low;//low就是基准左边为小于的数,右边为大于的数
}
浙公网安备 33010602011771号