冒泡排序

public class BubbleSort {

public static void main(String[] args) {
    int score[] = { 58, 79, 95, 47, 39, 68, 98,100 };
    Bubble(score);

}

public static void Bubble(int[] score) {

    for (int i = 0; i < score.length - 1; i++) {//sort number
        for (int j = 0; j < score.length - i - 1; j++) {//compare value
            if (score[j] < score[j + 1]) {
                int temp = score[j];
                score[j] = score[j + 1];
                score[j + 1] = temp;
            }
        }
        System.out.print("the " + (i + 1) + "  " + "sort:" + "    ");
        for (int a = 0; a < score.length; a++) {
            System.out.print(score[a] + "\t");
        }
        System.out.println("");
    }
    System.out.print("last result is:  ");
    for (int a = 0; a < score.length; a++) {
        System.out.print(score[a] + "\t");
    }
}

}

你可能感兴趣的:(排序,冒泡)