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

推荐订阅源

博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
量子位
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
L
LangChain Blog
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
U
Unit 42
Martin Fowler
Martin Fowler
aimingoo的专栏
aimingoo的专栏
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客

博客园 - John Yang

【转】批处理命令基础教程 《Transact-sql权威指南》学习日记 安装与配置IIS 设计原则 一些常见的C#面试问题和答案 什么是SQL注入式攻击 什么是手册报关 策略模式 C#入门(一) 什么是PMP认证 - John Yang - 博客园 [好文共享] 哈佛讲师讲授幸福:我们越来越富有为何仍不开心 设计模式之工厂模式 42个项目管理过程 项目管理过程组与知识领域表 背完这444句,你的口语绝对不成问题了 SQL SERVER性能优化 [白领栏目] 创造“我生命中的鼎盛之年”五大原则 【三星系列】真正的三星F278秘笈 让人生成功的49个细节
排序算法
John Yang · 2010-07-29 · via 博客园 - John Yang

1.冒泡排序法

冒泡排序算法核心循环代码

 1 for (int i = 0; i < num.Length - 1; i++)
 2 {
 3     for (int j = 0; j < num.Length - 1 - i; j++)
 4     {
 5          if (num[j] > num[j + 1])
 6          {
 7               int temp = num[j];
 8               num[j] = num[j + 1];
 9               num[j + 1= temp;
10          }
11      }
12  }

2.选择排序算法

代码

 1         private static int[] SelectionSort(int[] x)
 2         {
 3             int[] temp = x;
 4             int big = 0;
 5             int index = 0;
 6 
 7             for (int i = 0; i < x.Length; i++)
 8             {
 9                 index = i;
10 
11                 for (int j = i+1; j < x.Length; j++)
12                 {
13                     if (temp[j] > temp[index])
14                     {
15                         index = j; 
16                     }
17                 }
18 
19                 if (i != index)
20                 {
21                     big = temp[index];
22                     temp[index] = temp[i];
23                     temp[i] = big;
24                 }
25             }
26                         
27             return temp;
28         }