快排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就是基准左边为小于的数,右边为大于的数
}

 

posted @ 2022-04-16 21:15  半喜  阅读(107)  评论(0)    收藏  举报