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

推荐订阅源

V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
L
LangChain Blog
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
Y
Y Combinator Blog
月光博客
月光博客
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
小众软件
小众软件
H
Help Net Security
Last Week in AI
Last Week in AI
B
Blog RSS Feed
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog

博客园 - pysharp

openstack horizon api step by step understanding horizon's template path what can PsTools\psexec do! - pysharp What's New in Python3.0 - pysharp [转]利用adsutil.vbs脚本创建自定义web站点 我的2008. sql基础篇,不断更新中...... TypeConvert Demo javascript 调试器v1.0.0.0 Dundas Chart Demo For New User - pysharp c#面向对象中的继承初步认识 .net 集合类初步认识 c# 目录操作类 c# 文件操作类 - pysharp - 博客园 关于urlrewrite的小DEMO - pysharp - 博客园 c# 动态编译方法 c# 读取Excel到datable asp.net 下载和在线预览Excel的方法 简单使用nHibernate,新手练习用。
排序算法 c#实现
pysharp · 2008-01-22 · via 博客园 - pysharp

        上学的时候学算法,大体是知道了排序的工作原理,昨天写程序了突然发现原来明白和会写差很远,所以自己动手再写一次,我感觉快速排序的算法比冒泡和选择等的算法稍难以理解一点,不知道是我智商太低还是才疏学浅,把我写的快速排序方法,贴上来,仅供记忆。
        /// <summary>
        /// 快速排序算法
        /// </summary>
        /// <param name="array">待排序数组</param>
        /// <param name="low">起始位置</param>
        /// <param name="high">结束位置</param>
        public void QuickSort(int[] array, int low, int high)
        {           
            int pivot=array[low];            //支点,比较大小用。
            int left, right;       
            int temp;      //临时变量,记录比较到哪里完成了一轮交换
            left = low;
            right = high;

            if (low >= high)
            {
                return;
            }
            else{
                while (true) {
                    while (array[right] > pivot)           
                    {
                        right--;
                    }
                    while (array[left] < pivot)
                    {
                        left++;
                    }
                    if (left>=right)
                    {
                        temp=left;
                        break;
                    }
                    else
                    {
                        Swap(ref array[left], ref array[right]);
                    }
                }
                int length = array.Length;       //下边把每轮交换后的结果显示出来,看看快速排序是如何工作的
                for (int i = 0; i < length; i++)
                {
                    Console.Write("array[" + i.ToString() + "]=" + array[i].ToString()+";");
                }
                Console.WriteLine();
                QuickSort(array,low,temp-1);           /对分割完的数组继续调用自己,直到数组只有一个元素为止。
                QuickSort(array,temp+1,high);
            }
        }

        /// <summary>
        /// 交换两个数的值
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        public void Swap(ref int i, ref int j)  
        {
            int s;
            s = j;
            j = i;
            i = s;
        }