冒泡排序

import java.util.*;
public class Bubble{
    public int[] getBubble(int[] array){
        if(array == null || array.length == 0) return null;
        for(int i=0;i<array.length;i++){
            for(int j=i+1;j<array.length;j++){
                if(array[i]>array[j]){
                    int temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;

                }
            }
            
            
        }
        return array;
    }
    public static void main(String[] args){
        int[] array = {1,100,234,44,3,2,4,5};
        Bubble b = new Bubble();
        array = b.getBubble(array);
        System.out.println(Arrays.toString(array));
    }
}

 

posted @ 2018-07-04 23:04  樱圃  阅读(84)  评论(0编辑  收藏  举报