欢迎光临
我们一直在努力

c#算法——-(四)快速排序-.net教程,算法/线

建站超值云服务器,限时71元/月

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)
    sort(list,r+1,high);
  }
}
public class mainclass
{
  public static void main()
  {
   int[] iarrary=new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47};
   quicksorter q=new quicksorter();
   q.sort(iarrary,0,13);
   for(int m=0;m<=13;m++)
    console.writeline("{0}",iarrary[m]);
  }
}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » c#算法——-(四)快速排序-.net教程,算法/线
分享到: 更多 (0)

相关推荐

  • 暂无文章