6.5.2直接选择排序
2015-10-09 19:47
197 查看
package shuzu; public class ShuZu { public static void main(String[] args) { //直接选择排序 int arr[] = {6,7,2,9,3,5,4,1,8}; for(int j =arr.length-1; j > 0; j--) { int max = 0;//新定义数组中最大数的索引变量为max for(int i = 1;i <= j; i++)//数组中的数逐个与之值比较 { if(arr[max] < arr[i])//若小则将索引值付给max { max = i; } } int temp = arr[j]; //将本趟查找中的最大数放到最后 arr[j] = arr [max]; arr[max] = temp; } //遍历输出排序好的数组 for(int x : arr) { System.out.println(x); } } }
相关文章推荐
- Flex工程部署到Tomcat的步骤
- 压力测试
- UESTC 84 Binary Operations(位运算+DP)
- HDU3068最长回文 Manacher算法
- servlet的上传文件
- 高精度运算之加减乘
- ffmpeg SDK开发手册
- Codeforces 8B
- POJ 1010 STAMPS(dfs)
- ActionBar之自定义分享
- 【work】判断ip地址是否合法
- 重启docker服务器后 遇到 'device or resource busy'错误
- 启动fiddler8888被占用
- [Leetcode]Sum Root to Leaf Numbers
- error LNK2019: 无法解析的外部符号
- 用python3写一个华工SCUT连接的脚本
- ios之viewWithTag
- css 3d效果
- 依赖,关联
- Socket/Epoll主要流程对socket错误码正确处理