冒泡排序

public class maopaipaixu {
    public static void main(String[] args) {
        int [] num ={1,7,2,5,9,4,2,11,10,3};
        int[] sort = sort(num);
        System.out.println(Arrays.toString(sort));
    }

    private static int[] sort(int[] num) {
        for (int i = 0; i < num.length - 1; i++) {
            for (int j = 0; j < num.length - 1 - i; j++) {
                if (num[j] > num[j+1]) {
                    int temp = num[j];
                    num[j]=num[j+1];
                    num[j+1]=temp;
                }
            }
        }
        return num;
    }
}

 

posted @ 2021-02-07 09:57  我没有出家  阅读(44)  评论(0编辑  收藏  举报