C++ 快速排序

int partion(int a[],int low,int high)

{

	int key=a[low];

	while(low<high)

	{

		while (low<high&&key<a[high])

			high--;

		if(low<high)

		{

			a[low]=a[high];

			a[high]=key;

		}

		while (low<high&&key>a[low])

			low++;

		if(low<high)

		{

			a[high]=a[low];

			a[low]=key;

		}

	}

	return low;

}

void quick_sort(int a[],int low,int high)

{

	if(low<high)

	{

		int mid=partion(a,low,high);

		quick_sort(a,0,mid-1);

		quick_sort(a,mid+1,high);

	}

}


你可能感兴趣的:(快速排序)