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

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

博客园 - 三文鱼

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

 1class MergeSortSample
 2    {
 3        public void MergeSort(int[] values, int begin, int end)
 4        {
 5            if (begin < end)
 6            {
 7                int mid = (begin + end) / 2;
 8                MergeSort(values, begin, mid);
 9                MergeSort(values, mid + 1, end);
10                Merge(values, begin, mid, end);                
11            }

12        }

13
14        public void Merge(int[] values, int begin, int mid, int end)
15        {
16            int length1 = mid - begin + 1;
17            int length2 = end - mid;
18            int[] values1 = new int[length1 + 1];
19            int[] values2 = new int[length2 + 1];
20            for (int i = 0; i < length1; i++)
21            {
22                values1[i] = values[i + begin];
23            }

24            for (int i = 0; i < length2; i++)
25            {
26                values2[i] = values[i + mid + 1];
27            }

28
29            values1[length1] = int.MaxValue;
30            values2[length2] = int.MaxValue;
31                        
32            for (int i = 0, j = 0, k = begin; k <= end; ++k)
33            {
34                if (values1[i] <= values2[j])
35                {
36                    values[k] = values1[i];
37                    ++i;
38                }

39                else
40                {
41                    values[k] = values2[j];
42                    ++j;
43                }

44            }

45        }

46
47        static void Main()
48        {
49            int[] values = 4375890126 };
50
51            MergeSortSample mergeSort = new MergeSortSample();
52            mergeSort.MergeSort(values, 0, values.Length - 1);
53
54            foreach (int v in values)
55            {
56                Console.Write(v + " ");
57            }

58            Console.ReadKey();
59        }

60    }