JAVA冒泡排序

public class Arrange{
    public void sort(int[] a) {
        int temp = 0;
        for (int i = a.length - 1; i > 0; --i) {
            for (int j = 0; j < i; ++j) {
                if (a[j + 1] < a[j]) {
                    temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
            System.out.println(temp);
        }

    }

    public static void main(String[] args) {
        Arrange sc = new Arrange();
        int arr[]={23,99,44,78,1,12};
        sc.sort(arr);
    }
}

 

posted @ 2017-10-23 18:50  ichimoku  阅读(325)  评论(0编辑  收藏  举报