Bubble sort

public class Main {
    public static void main(String[] args) {
        int [] arr = {9,8,7,6,5,4,3,2,1,0};
        bubbleSort(arr);
        for(int i:arr)
            System.out.println(i);
    }

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

posted on 2010-07-04 22:34  sunliho  阅读(117)  评论(0编辑  收藏  举报