标签:
package lianxi; public class BubbleSort { public static void main(String[] args) { int[] array = {12,23,3,5,65,67,34,23,5,7,789,435,2,4}; //对数组冒泡排序 for(int i = 0;i < array.length - 1; i ++) { for(int j = 0;j < array.length - i - 1; j ++) { if (array[j] > array[j + 1]) { array[j] = array[j] + array[j + 1]; array[j + 1] = array[j] - array[j + 1]; array[j] = array[j] - array[j + 1]; } } //对每趟排序结果打印 System.out.println("第"+ i+ "趟排序结果"); for(int k = 0; k < array.length; k ++) { System.out.print(array[k] + " "); } System.out.println(); } } }
标签:
原文地址:http://www.cnblogs.com/Kermit-Li/p/4443376.html