冒泡排序
2016-04-22 12:40
344 查看
package sun; //从最右边开始,较小的元素一直往左边移动 //最左边的元素为最后的位置 public class Sort { public static void bubble(int[] a) { for (int i = 0; i < a.length; i++) { for (int j = a.length - 1; j > i; j--) { if (a[j] < a[j - 1]) { int temp = a[j - 1]; a[j - 1] = a[j]; a[j] = temp; } } } } public static void main(String[] args) { int[] arr = { 9, 8, 4, 3, 2, 1 ,7, 6, 5,}; bubble(arr); for (int a : arr) System.out.println(a); } }
相关文章推荐
- MMORPG服务器架构
- Intent
- 线程的生命周期
- Matlab调试功能详解
- 苹果iTunes电影和iBooks商店被中国关闭
- 苹果iTunes电影和iBooks商店被中国关闭
- R语言︱H2o深度学习的一些R语言实践——H2o包
- shell脚本中一些特殊符号
- [LeetCode] Reverse String 翻转字符串
- windows服务(installutil.exe)报错。异常来自 HRESULT:0x80131515
- Best Time to Buy and Sell Stock
- python解析pcap转储为sqlite
- 【图像处理】基本的全局图像灰度变换
- EF linq多表查询统计demo
- UINavigationBar的Back按钮手势失灵解决办法
- 一个不错的shell 脚本教程 入门级
- Java---IO加强(1)
- Java---IO加强(1)
- docke跨主机通信之gre隧道
- 使用SpringMVC和Mybatis