选择排序、冒泡排序、工具类排序
2016-06-10 15:17
239 查看
package com.test.test; import java.util.Arrays; /** * [说明/描述] * * @author CaiHaiming * @date 2016-6-4 下午7:00:07 * @company chm * @version 1.0 * @copyright copyright (c) 2016 */ public class Sort1 { public static void main(String[] args) { int[] arr = { 123, 2, 23, 134, 1, 123, 12312 }; sort1(arr); System.out.println(Arrays.toString(arr)); } public static void sort1(int[] arr) { for (int i = 0; i < arr.length - 1; i++) { for (int j = i + 1; j < arr.length; j++) { if (arr[i] > arr[j]) { Sort2.swap(arr, i, j); } } } } }
package com.test.test;import java.util.Arrays;/** * [说明/描述] * * @author CaiHaiming * @date 2016-6-4 下午7:00:07 * @company chm * @version 1.0 * @copyright copyright (c) 2016 */public class Sort2 {<span style="white-space:pre"> </span>public static void main(String[] args) {<span style="white-space:pre"> </span>int[] arr = { 123, 2, 23, 134, 1, 123, 12312 };<span style="white-space:pre"> </span>sort1(arr);<span style="white-space:pre"> </span>System.out.println(Arrays.toString(arr));<span style="white-space:pre"> </span>}<span style="white-space:pre"> </span>public static void sort1(int[] arr) {<span style="white-space:pre"> </span>for (int i = 0; i < arr.length - 1; i++) {<span style="white-space:pre"> </span>for (int j = 0; j < arr.length - i - 1; j++) {<span style="white-space:pre"> </span>if (arr[j] > arr[j + 1]) {<span style="white-space:pre"> </span>swap(arr, j, j + 1);<span style="white-space:pre"> </span>}<span style="white-space:pre"> </span>}<span style="white-space:pre"> </span>}<span style="white-space:pre"> </span>}<span style="white-space:pre"> </span>public static void swap(int[] arr, int i, int j) {<span style="white-space:pre"> </span>int temp = arr[i];<span style="white-space:pre"> </span>arr[i] = arr[j];<span style="white-space:pre"> </span>arr[j] = temp;<span style="white-space:pre"> </span>}}
package com.test.test;import static java.util.Arrays.sort;import java.util.Arrays;/** * [说明/描述] * * @author CaiHaiming * @date 2016-6-4 下午7:00:07 * @company chm * @version 1.0 * @copyright copyright (c) 2016 */public class Sort3 {<span style="white-space:pre"> </span>public static void main(String[] args) {<span style="white-space:pre"> </span>int[] arr = { 123, 2, 23, 134, 1, 123, 12312 };<span style="white-space:pre"> </span>sort(arr);<span style="white-space:pre"> </span>System.out.println(Arrays.toString(arr));<span style="white-space:pre"> </span>}}
相关文章推荐
- Increasing Java Heap Size — Out of memory error — java -Xmx3000M -Xms1500M -XshowSettings:all
- shell中${}的妙用
- cocos2dx之加载瓦片地图tmx
- 正则表达式小总结
- pandas SettingWithCopyWarning
- SpringMVC之MVC模型(六)
- Amortized analysis平摊分析——记算法导论视频总结
- 名词解释
- 二分查找
- RocEDU.阅读.写作《苏菲的世界》书摘(七)
- linux下SVN+apache搭建
- 解决maven中servlet-api.jar和容器自带的servlet-api.jar的依赖冲突
- rsync的配置和以rsync的daemon工作模式传输数据
- 初识java线程池
- 九度OJ 1002
- graphx初涉,结合源码学习一
- android面包屑导航栏的实现
- Linux系统信息显示命令
- jQueryt过滤选择器
- 使用MyBatis对表执行CRUD操作