首页 > 编程语言 > 详细

冒泡排序例题

时间:2016-02-29 19:38:39      阅读:438      评论:0      收藏:0      [点我收藏+]
技术分享
 1 int []g=new int[] {49,38,65,97,76,13,27,49};
 2             int m=0;
 3             System.out.print("原始顺序");
 4             for(int t:g)
 5             {
 6                 System.out.print(t+" ");
 7             }System.out.println();
 8             for(int i=0;i<g.length-1;i++)
 9             {
10                 for(int j=0;j<g.length-1-i;j++)
11                 {
12                     if(g[j]>g[j+1])
13                     {
14                         int x=g[j];
15                         g[j]=g[j+1];
16                         g[j+1]=x;
17                     }
18                     m++;
19                 }
20                 System.out.print((i+1)+"次循环");    
21                 for(int t:g)
22                 {
23                     System.out.print(t+" ");
24                 }System.out.println();
25             }        
26             System.out.println("循环了"+m+"次");
View Code

技术分享

冒泡排序例题

原文:http://www.cnblogs.com/beens/p/5228575.html

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