冒泡排序

public class Bubbling {
    public static void mp(int num[]){
        int swap = 0 ;

        //排序前
        System.out.println("==== 排序前 ====");
        for (int i = 0; i < num.length ; i++) {
            System.out.println(num[i]);
        }
        
        //排序后
        for (int i = 0; i < num.length; i++) {
            for (int j = 0; j < num.length ; j++) {
               if(num[j] > num[i]){
                   swap = num[i];
                   num[i] = num[j];
                   num[j] = swap;
               }
            }

        }
        System.out.println("==== 排序后 ====");
        for (int i = 0; i < num.length ; i++) {
            System.out.println(num[i]);
        }
    }
    public static void main(String[] args) {
        int[] nums = {22,30,59,89,64,3,100};
        mp(nums);

    }
}

 

posted @ 2019-01-09 09:56  华艳  阅读(85)  评论(0编辑  收藏  举报