黑马程序员技术交流社区

标题: 冒泡排序 [打印本页]

作者: liming_heima    时间: 2015-6-20 17:52
标题: 冒泡排序
public class Sort {
        /**
         * 冒泡排序
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                int[] sort = new int[] { 1, 23, 4, 6, 3, 2, 8, 9 };
                paixu(sort);
                int m = 0 ;
                ++m;
                System.out.println("m"+m);
                // 遍历输出数组
                for (int i = 0; i < sort.length; i++) {
                        System.out.println(sort[i]);
                }
        }
        public static int[] paixu(int[] sort) {
                System.out.println("数组的长度是"+sort.length);
                int temp;
                for (int i = 0; i < sort.length; i++) {
                        for (int j = 0; j < i; j++) {
                                if (sort[i] < sort[j]) {
                                        temp = sort[i];
                                        sort[i] = sort[j];
                                        sort[j] = temp;
                                }
                        }
                }
                return sort;
        }
}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2