C#库函数里包含快速排序吗?求一个应用例子

来源:百度知道 编辑:UC知道 时间:2024/05/24 13:05:21

using System;

namespace QuickSorter
{
public class QuickSorter
{
private void Swap(ref int l,ref int r)
{
int s;
s=l;
l=r;
r=s;
}
public void Sort(int [] list,int low,int high)
{
int pivot;
int l,r;
int mid;
if(high<=low)
return;
else if(high==low+1)
{
if(list[low]>list[high])
Swap(ref list[low],ref list[high]);
return;
}
mid=(low+high)>>1;
pivot=list[mid];
Swap(ref list[low],ref list[mid]);
l=low+1;
r=high;
do
{
while(l<=r&&list[l]<pivot)
l++;
while(list[r]>=pivot)
r--;
if(l<r)
Swap(ref list[l],ref list[r]);
}while(l<r);
list[low]=list[r];
list[r]=pivot;
if(low+1<r)
Sort(list,low,r-1);
if(r+1<high)