Java-冒泡排序

冒泡排序

public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = { 11, 15, 14, 18, 22, 11, 50 };
        int temp = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}

 

posted @ 2022-01-05 18:32  宝码哥  阅读(24)  评论(0)    收藏  举报