冒泡算法
2015-08-05 19:27
369 查看
冒泡排序
/** * 冒泡算法 * Created by xueping.you on 15-8-5. */ public class BubbleSort { private final static Logger logger = LoggerFactory.getLogger(BubbleSort.class); public static void bubbleSort(int [] unsortArray){ for(int i=0; i<unsortArray.length; i++){ for(int j=0; j<unsortArray.length-i-1; j++){ int temp = unsortArray[j]; if(unsortArray[j]>unsortArray[j+1]){ unsortArray[j] = unsortArray[j+1]; unsortArray[j+1] = temp; } } } } public static void main(String []args){ int [] array = new int[]{12,10,2,45,31,56,1,9}; logger.info("before:{}" , array); bubbleSort(array); logger.info("after:{}", array); } }
result:
19:26:20.928 [main] INFO com.qyou.data.arithmetic.BubbleSort - before:[12, 10, 2, 45, 31, 56, 1, 9]
19:26:20.938 [main] INFO com.qyou.data.arithmetic.BubbleSort - after:[1, 2, 9, 10, 12, 31, 45, 56]
相关文章推荐
- 动易2006序列号破解算法公布
- 文件遍历排序函数
- C#选择排序法实例分析
- Ruby实现的矩阵连乘算法
- C#插入法排序算法实例分析
- C#实现Datatable排序的方法
- 超大数据量存储常用数据库分表分库算法总结
- SQLSERVER的排序问题结果不是想要的
- Windows Powershell排序和分组管道结果
- C#数据结构与算法揭秘二
- C#冒泡法排序算法实例分析
- C#通过IComparable实现ListT.sort()排序
- C#选择法排序实例分析
- 算法练习之从String.indexOf的模拟实现开始
- C#算法之关于大牛生小牛的问题
- SQL学习笔记四 聚合函数、排序方法
- C#实现的算24点游戏算法实例分析
- C#对list列表进行随机排序的方法
- 一根网线内的8根线哪4根是传输数据的,哪四根是防干扰的