//快速排序的具体过程如下:
//1:在待排序的n个记录中,任取一个作为基准,把数组分为两部分,第一组的排序码都小于或等于该排序码,第二组的排序码,都大于或等于该排序码,并把该基准放在两组中间。
2:采用同样的方法分别对左右两组进行排序//快速排序的具体过程如下:
//1:在待排序的n个记录中,任取一个作为基准,把数组分为两部分,第一组的排序码都小于或等于该排序码,第二组的排序码,都大于或等于该排序码,并把该基准放在两组中间。
2:采用同样的方法分别对左右两组进行排序,直到所有的记录都排到适当的位置。
///快速递归排序
privatestaticvoid QuickSort(int[] R, int low, int high)
{
int pivotLoc = 0;
if (low < high)
{
pivotLoc = Partition(R, low, high);
QuickSort(R, low, pivotLoc - 1);
QuickSort(R, pivotLoc + 1, high);
}
}
privatestaticint Partition(int[] R, int low, int high)
{
int temp = R[low];
while (low < high)
{
if (low < high && temp <= R[high])
{
high--;
}
R[low] = R[high];
if (low < high && R[low] <= temp)
{
low++;
}
R[high] = R[low];
}
R[low] = temp;
return low;
}
//快速非递归排序
publicstaticvoid QuickSort(int [] R,int Low,int High,Stack<int> stack)
{
int low = Low;
int high = High;
int temp = R[low];
while (high > low)
{
while (low < high && temp <= R[high])
{
high--;
}
if (high > low)
{
R[low] = R[hi
c#快速排序算法 来自淘豆网m.daumloan.com转载请标明出处.