选择排序--经典
2014-01-02 19:37
260 查看
public static void selectSort3(Comparable[] array) { System.out.println("===========Insert Sort Started==========="); Comparable temp; int min; for (int index = 0; index < array.length; index++) { // 假定第一个元素为最小元素 min = index; // 循环遍历元素,每遍历一个元素,与当前最小元素比较,若此元素比当前最小元素小,则将此元素置为最小元素 for (int time = index + 1; time < array.length; time++) { if (array[time].compareTo(array[min]) < 0) { min = time; } } // 遍历一遍,找到一个最小元素,把此最小元素放在数组的第一个位置 if (min != index) { temp = array[index]; array[index] = array[min]; array[min] = temp; } } System.out.println("The array after sorted...."); System.out.println(Arrays.toString(array)); System.out.println("============Insert Sort Ended============"); }
相关文章推荐
- MySQL 添加列,修改列,删除列
- Activity生命周期总结
- 左旋字符串
- MySQL 添加列,修改列,删除列
- TheBrain_windows_7_0_4_5+crack 安装记录
- A Comparison of the OSI and TCP/IP Reference Models
- xunsearch 迅搜初探
- 分析kernel的initcall函数
- 用SSH连接SSH连接nitrous.io
- shoelace源代码分析,bochs调试 readkernel()函数
- 串匹配算法KMP详解
- bubbleSort
- Vector介绍
- UltraGrid单元格放多个图片
- BeautyEye主题使用中BETitlePane的标题栏图标按钮个性修改
- SharePoint 2013 自定义翻页显示列表项
- C++ arraylist实现
- Linq学习__05__查询表达式和方法查询比较
- uva 755 - 487--3279
- amazon s3 的用户验证 access-key, secrete-key