C#——快速排序

方法

public static void QuickSort(int low, int high, int[] a) // 快速排序
{
	if(low >= high) //
	{
		return;
	}
	int first = low;
	int last = high;
	int key = a[first];//用字表的第一个记录作为基准

	while(first < last)
	{
		while(first < last && a[last] >= key)
		{
			--last;
		}

		a[first] = a[last];//将比第一个小的移到低端

		while(first < last && a[first] <= key)
		{
			++first;
		}

		a[last] = a[first];//将比第一个大的移到高端
	}

	a[first] = key;//

	QuickSort(low, first-1 ,a);
	QuickSort(first+1, high, a);
}


posted @ 2017-12-26 15:18  养鼠的猫  阅读(85)  评论(0编辑  收藏  举报