冒泡排序

2020-06-10  本文已影响0人  JayMeWangGL

实现原理


实现方法


实现代码

public class Bubble_Sort {

    public static void Bubble_Sort(int[] array){
        int temp=0;
        if (array==null||array.length<=0){
            return;
        }
        int length = array.length;
        for (int i = 0; i < length; i++) {

            for (int j = 0;j<length-i-1;j++){
                if (array[j]>array[j+1]){
                    temp=array[j+1];
                    array[j+1]=array[j];
                    array[j]=temp;
                }
            }
        }
    }
    public static void main(String[] args) {
        int[] array = {3,44,38,5,47,15,36,26,27,2,46,4,19,50,48};

        Bubble_Sort(array);
        System.out.println(Arrays.toString(array));
    }
}
上一篇下一篇

猜你喜欢

热点阅读