选择排序
2015-06-27 14:26
246 查看
/** * Created by xuxiaoyu on 2015/6/25. */ //选择排序:比如在一个长度为N的无序数组中,在第一趟遍历N个数据,找出其中最小的数值与第一个元素交换, //第二趟遍历剩下的N-1个数据,找出其中最小的数值与第二个元素交换......第N-1趟遍历剩下的2个数据, //找出其中最小的数值与第N-1个元素交换,至此选择排序完成 public class SelectionSort { public static void main(String[] args) { int a[] = { 2, 5, 8, 3, 2, 9, 7, 6, 1, 4,3333,22 }; int temp; for (int i = 0; i < a.length; i++) for (int j = i + 1; j < a.length; j++) { if (a[i] > a[j]) { temp = a[j]; a[j] = a[i]; a[i] = temp; } } for (int k = 0; k < a.length; k++) System.out.print(a[k] + "、"); } }
相关文章推荐
- 《Windows服务器配置与管理》------磁盘管理
- 统计机器学习笔记——感知机(1)
- 日语学习之沪江N3基础 20150627 -7
- cocos2dx-3.3 网络编程(CURL+PHP) NO.1 写好PHP代码
- 项目笔记:5.利用nginx七层分发器实现基于内容的分发
- ruby-Hash
- Java数据结构 Collections的一些方法介绍
- 建立名称服务器
- 微信支付趟过的坑
- head&&tail
- K-means算法Java实现
- TextView 多文字字体颜色及多事件监听
- 6.27 洗刷刷 oj 运算符重载 矩阵之和
- HDFS学习笔记(1)初探HDFS
- 闲聊
- Windows服务器配置与管理------远程桌面管理
- C++经典面试题(六)
- 二分查找
- Sort Colors
- js数组与 json 的区别