冒泡排序
2016-05-15 10:49
183 查看
以前在学习数据结构时,里面有很多排序方法其中就有冒泡排序。当时看着挺难得 这个和那个交换的。现在重新审视一下发现原来如此的简单⊙﹏⊙b汗 哎 真不知道当时的自己是怎么学的!o(╯□╰)o
1 static void Main(string[] args)
2 {
3 int[] a ={ 2, 43, 45, 23, 12, 34, 56, 87, 45 };
4 int max = 0;
5 for (int i = 0; i < a.Length; i++)
6 {
7 for (int j = 0; j < a.Length - 1; j++)
8 {
9 if (a[i] < a[j])//这是从小到大,如果是从大到小 a[i] > a[j] 即可
10 {
11 max = a[i];
12 a[i] = a[j];
13 a[j] = max;
14 }
15 }
16 }
17 //打印排序后的数组
18 for (int i = 0; i < a.Length; i++)
19 {
20 Console.WriteLine(a[i]);
21 }
22 Console.ReadKey();
23 }
24 }
1 static void Main(string[] args)
2 {
3 int[] a ={ 2, 43, 45, 23, 12, 34, 56, 87, 45 };
4 int max = 0;
5 for (int i = 0; i < a.Length; i++)
6 {
7 for (int j = 0; j < a.Length - 1; j++)
8 {
9 if (a[i] < a[j])//这是从小到大,如果是从大到小 a[i] > a[j] 即可
10 {
11 max = a[i];
12 a[i] = a[j];
13 a[j] = max;
14 }
15 }
16 }
17 //打印排序后的数组
18 for (int i = 0; i < a.Length; i++)
19 {
20 Console.WriteLine(a[i]);
21 }
22 Console.ReadKey();
23 }
24 }
1 static void Main(string[] args) 2 { 3 int[] a ={ 2, 43, 45, 23, 12, 34, 56, 87, 45 }; 4 int max = 0; 5 for (int i = 0; i < a.Length; i++) 6 { 7 for (int j = 0; j < a.Length - 1; j++) 8 { 9 if (a[i] < a[j])//这是从小到大,如果是从大到小 a[i] > a[j] 即可 10 { 11 max = a[i]; 12 a[i] = a[j]; 13 a[j] = max; 14 } 15 } 16 } 17 //打印排序后的数组 18 for (int i = 0; i < a.Length; i++) 19 { 20 Console.WriteLine(a[i]); 21 } 22 Console.ReadKey(); 23 } 24 }
相关文章推荐
- ICTCLAS2016 linux C++版本 使用教程 Eclipse下开发C/C++程序之头文件,库文件引用
- Maven 引用lib下jar
- adapterView(适配器试图)-ListView
- 浅析Java内存模型与垃圾回收
- iris数据的KNN实现
- 存储过程和SQL语句比较
- Javascript的无new构建实例详解
- iOS--上传AppStore时遇到的10个大坑
- OpenCV246人脸检测
- Linux中ifcfg-eth0配置参数解释
- [WINCE|VS2008] 用在PC上调试WINCE程序
- Material Design(十一)--CoordinatorLayout和自定义视图
- 不想只与你梦里相见
- R语言执行脚本的几种命令
- 不想只与你梦里相见
- Linux的文件类型
- Program3_S
- Material Design(十)--CoordinatorLayout和App Bar
- 理解Bitcode:一种中间代码
- Oracle中的一些查询语句及其执行顺序