码迷,mamicode.com
首页 > 编程语言 > 详细

冒泡排序

时间:2016-12-01 22:06:47      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:rgs   区间   new   ++   stat   int   冒泡   core   缩小   

public static void main(String[] args) {
        int[] score =new int[] { 88, 35, 75, 87, 20, 90, 2, 756 };
        for (int i = 0; i < score.length - 1; i++) { // 最多做n-1趟排序
            
            for (int j = 0; j < score.length - i - 1; j++) { // 对当前无序区间score[0......length-i-1]进行排序(j的范围很关键,这个范围是在逐步缩小的)
                
                if (score[j] > score[j + 1]) { // 把小的值交换到后面
                    int temp = score[j];
                    score[j] = score[j + 1];
                    score[j + 1] = temp;
                }
            }
            
        }
        System.out.print("最终排序结果:");
        for (int a = 0; a < score.length; a++) {
            System.out.print(score[a] + "\t");
        }
    }

}

 

冒泡排序

标签:rgs   区间   new   ++   stat   int   冒泡   core   缩小   

原文地址:http://www.cnblogs.com/bingo584235807/p/6123282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!