首页 > 编程语言 > 详细

java冒泡排序算法

时间:2015-09-24 09:31:11      阅读:142      评论:0      收藏:0      [点我收藏+]
 1 /**
 2  * 冒泡排序算法:每次
 3  * @author shaobn
 4  * @description 每次都会确定一个最大的值 即固定了,所以会每次-i;
 5  */
 6 public class Test1 {
 7     
 8     public static void main(String[] args) {
 9         int[] a=  {20,23,11,13,35,34,657};
10         Method(a);
11     }
12     public static void Method(int[] a){
13         int temp =0;
14         for(int i = 1;i<a.length;i++){
15             for(int j =0;j<a.length-i;j++){
16                 if(a[j]>a[j+1]){
17                     temp = a[j];
18                     a[j] = a[j+1];
19                     a[j+1] = temp;    
20                 }
21             }
22         }
23         for(int i=0;i<a.length-1;i++){
24             System.out.println(a[i]);
25  }        
26         
27     }
28 }

 

java冒泡排序算法

原文:http://www.cnblogs.com/assassin666/p/4834208.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!