冒泡排序
2015-11-04 11:09
197 查看
1.冒泡排序算法,增加flag标记
/** * Created by xingxing.duan on 2015/11/4. */ public class BubbleSort { private static void bubbleSort(int[] matrix) { boolean flag = true; for (int i = 0; i < matrix.length && flag; i++) { flag = false; for (int j = 1; j < matrix.length - i; j++) { if (matrix[j - 1] > matrix[j]) { int tmp = matrix[j - 1]; matrix[j - 1] = matrix[j]; matrix[j] = tmp; flag = true; } } } } public static void main(String[] args) { int[] matrix = new int[]{3, 4, 8, 7, 6, 10, 9,9,9,10,10,4}; bubbleSort(matrix); for (int i : matrix) { System.out.print(i + " "); } } }
相关文章推荐
- 判断所有的字符不相同
- EasyUI form success IE
- JavaScript闭包(closure)
- Android中Service(服务)详解
- Adobe Air 获取启动参数
- 【Leetcode】之Letter Combinations of a Phone Number
- 黑马程序员——java基础语法(一)---关键字、标识符、注释、常量、变量、运算符
- jQuery 控制input及select的应用
- JavaScript闭包(closure)
- Objective-C Blocks Quiz
- Android Hook框架Xposed原理与源代码分析
- 整理开源协议的比较(BSD,Apache,GPL,LGPL,AGPL,MIT,Zlib/Libpng协议)
- win7自带的截图工具在截图时怎么将截的图片发送到桌面上?
- 苹果向开发者发布OS X 10.11.2 El Capitan 第二个测试版
- 多线程讲解韩老师
- mybatis问题汇总
- Apache shutdown unexpectedly启动错误解决方法
- 数据库图片导入
- Spring中配置和读取多个Properties文件-- PropertyPlaceholderConfigurer
- html在一个页面显示另一个页面的部分内容