继续上图和代码
package com.lyj.sort.insert; public class BubbleSort { /** * @param args */ public static void main(String[] args) { int[] array = { 49, 38, 65, 97, 76, 13, 27 }; // 排序前 System.out.print("排序前: "); for (int i : array) { System.out.print(i + " "); } System.out.println(); // 排序 bubbleSort(array); // 排序后 System.out.print("排序后: "); for (int i : array) { System.out.print(i + " "); } } private static void bubbleSort(int[] array) { for (int i = 0; i < array.length - 1; i++) { for (int j = 0; j < array.length - 1; j++) { if (array[j] > array[j + 1]) { int temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; } } // System.out.print("第 " + i + "次排序: "); // for (int index : array) { // System.out.print(index + " "); // } // System.out.println(); } } }