排序算法--冒泡排序

来源:互联网 发布:linux 查看登陆ip 编辑:程序博客网 时间:2024/06/06 09:47

个人整理的冒泡排序算法

/** * 冒泡排序 *  * 从头比较相邻两个数,较大的在前的话与较小的互换 */public static int[] test03(int[] a) {int temp = 0;for (int i = 0; i < a.length - 1; i++) {for (int j = 0; j < a.length - i - 1; j++) {if (a[j] > a[j + 1]) { // 判断// 交换temp = a[j];a[j] = a[j + 1];a[j + 1] = temp;}}}return a;}empty
原创粉丝点击