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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
雷峰网
雷峰网
博客园 - 叶小钗
V
V2EX
博客园 - Franky
博客园_首页
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
S
SegmentFault 最新的问题
B
Blog RSS Feed
博客园 - 【当耐特】
D
Docker
N
Netflix TechBlog - Medium

博客园 - 三文鱼

叶问 弧线枪法 我是传奇 赤壁~之战 也说动物园展示蟒蛇吃活鸡 终于知道g9是谁了 人生的蝴蝶效应 杭州之行 广州车展 西安之行 变形金刚真是火 C#写的几个基本的排序算法(三) C#写的几个基本的排序算法(一) 数据库惊现"NULL" 换了个计数器 应该了解的垃圾收集机制(二) 应该了解的垃圾收集机制(一) 中国队输了 别把代码写成“密码”
C#写的几个基本的排序算法(二)
三文鱼 · 2007-06-27 · via 博客园 - 三文鱼

快速排序:

 1class QuickSortSample
 2    {
 3        CommonFunctions<int> _funcs = new CommonFunctions<int>();
 4
 5        public void Sort(int[] values, int begin, int end)
 6        {
 7            if (begin < end)
 8            {
 9                int p = Partition(values, begin, end);
10
11                Sort(values, begin, p - 1);
12                Sort(values, p + 1, end);
13            }

14        }

15
16        public int Partition(int[] values, int begin, int end)
17        {
18            int i = begin - 1;
19            
20            for (int j = begin; j < end ; j++)
21            {
22                if (values[j] < values[end])
23                {
24                    i++;
25                    _funcs.ExchangValues(ref values[j], ref values[i]);
26                }

27            }

28
29            i++;
30            _funcs.ExchangValues(ref values[i], ref values[end]);
31
32            return i;
33        }

34
35        static void Main()
36        {
37            int[] values = {4375890126 };
38
39            QuickSortSample quickSort = new QuickSortSample();
40            quickSort.Sort(values, 0, values.Length - 1);
41
42            foreach (int i in values)
43            {
44                Console.Write(i + "  ");
45            }

46        }

47    }