冒泡排序

2017-01-11  本文已影响0人  Veteor

将数组相邻的两个元素比较,将小的数和大的数交换位置,否则不交换

public static void bubbleSort(int []a){
        for(int i = 0;i < a.length-1; i++){
            for(int j = i+1; j<a.length; j++){
                if(a[i]>a[j]) {
                    int temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读