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

推荐订阅源

V
Visual Studio Blog
博客园 - 司徒正美
博客园_首页
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
I
InfoQ
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
L
LangChain Blog
Last Week in AI
Last Week in AI
A
About on SuperTechFans
B
Blog
博客园 - 叶小钗
雷峰网
雷峰网
H
Help Net Security
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
博客园 - 【当耐特】
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - stone

release 版本dll的调试 dead lock in thread pool Excel C# Automation 如何让iframe 自动适应窗口的高度 自定义Silverlight toolkit 里面的 Column Chart 的data point 二叉树算法题 How to do live debug the Managed code in Windows Phone 7 单链表操作相关算法 BUG: "Old format or invalid type library" error when automating Excel on 64 bit server 2008 - stone enable Assembly Load Trace 不合法的XML字符必须被替换为相应的实体 - stone - 博客园 如何修改 VS 自动生成的 COM interop dll VS中Sos调试扩展简介 (转帖) Sql server 2005 connection string - stone Get depth of BTree Quick sort C# code use the network trace, from msdn. - stone 字节流编码获取原来这么复杂,但也很简单 通过DataTable获得表的主键 让IE支持自己的协议
Quick sort C# code(2)
stone · 2008-07-01 · via 博客园 - stone

public class QuickSortNonRecursion
{
       public int Split(int[] data,int low,int high)
      {
                if(data == null) throw new ArgumentNullException();
                if(low<0 || high >= data.length) throw new ArgumentOutOfRangeException();

         int pivot = data[low];
         while(low < high){
                 while(low < high && data[high] >= pivot) high--;
                 data[low] = data[high];
                 while(low < high && data[low]<= pivot) low++;
                 data[high] = data[low];
         }
          data[low] = pivot;
          return low;
}

public void QuickSort(int[] data, int low, int high)
{
        if(low < high)
        {
              Stack<int> stc = new Stack<int>();
              int pivot = Split(data,low,high);
              stc.push(low);
              stc.push(pivot -1);
              stc.push(pivot +1);
              stc.push(high);

              while(stc.count>0)
              {
                    high = stc.pop();
                    low = stc.pop();
                    int temp;
                    if(low<high)
                    {
                         pivot = Split(data,low,high);
                         temp = pivot-1;
                         if(low < pivot)
                         {
                               stc.push(low);
                               stc.push(temp);
                         }
                         temp = pivot +1;
                         if(high>pivot)
                         {
                               stc.push(temp);
                               stc.push(high);
                         }
                     }
              }
         }
}