快速排序


void swap(int *a,int *b){
	int temp=*a;
	*a=*b;
	*b=temp;
}
void quickSort(int *a,int left,int right){
	if(left>right)
		return;
	int temp=a[left];
	int i=left;
	int j=right;
	while(i!=j){
		while(a[j]>=temp&&i<j)
			j--;
		while(a[i]<=temp&&i<j)
			i++;
		if(i<j){
			swap(a+i,a+j);
		}
	}
	a[left]=a[i];
	a[i]=temp;
	quickSort(a,left,i-1);
	quickSort(a,i+1,right);
}

  

posted @ 2019-03-22 17:31  赵钱富贵  阅读(147)  评论(0编辑  收藏  举报