惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
美团技术团队
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
Jina AI
Jina AI
博客园_首页
M
MIT News - Artificial intelligence
D
DataBreaches.Net
L
LangChain Blog
宝玉的分享
宝玉的分享
F
Fortinet All Blogs
A
About on SuperTechFans
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
腾讯CDC
Vercel News
Vercel News
雷峰网
雷峰网
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】

博客园 - 阿伟

转一个哥们的日记看了让你吐血 IT技术和职位小览和应聘注意事项 生活中的笑话 男人25岁前的忠告(转) 经典承诺 怎样对待男人和女人之间关系 插入排序(C#) 如何关闭常见端口(113、4899、389、6129等端口) 一些字符串操作的常用用法 - 阿伟 - 博客园 选择排序(C#) C#常用函数 几个网络术语!~ net命令研究 股票术语集锦 找女朋友的标准,男人不看后悔一辈子!!! DataGrid自定义分页存储过程 男生给女生最牛B的告白 一个光棍的呐喊! 令人呕吐的几则笑话^_^
快速排序(c#)
阿伟 · 2006-03-04 · via 博客园 - 阿伟

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]);  
  }

 }



}