码迷,mamicode.com
首页 > 其他好文 > 详细

冒泡排序

时间:2014-05-27 17:09:26      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:c   class   blog   http   a   int   

public class BubbleSort{
public static void main(String[] args){
int score[] = {67, 69, 75, 87, 89, 90, 99, 100};
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("第" + (i + 1) + "次排序结果:");
for(int a = 0; a < score.length; a++){
System.out.print(score[a] + "\t");
}
System.out.println("");
}
System.out.print("最终排序结果:");
for(int a = 0; a < score.length; a++){
System.out.print(score[a] + "\t");
}
}
}

 

bubuko.com,布布扣

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

冒泡排序,布布扣,bubuko.com

冒泡排序

标签:c   class   blog   http   a   int   

原文地址:http://www.cnblogs.com/wuyuankun/p/3753059.html

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