Chinaunix首页 | 论坛 | 博客
  • 博客访问: 193453
  • 博文数量: 37
  • 博客积分: 510
  • 博客等级: 入伍新兵
  • 技术积分: 230
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-02 19:49
文章分类

全部博文(37)

文章存档

2011年(37)

分类: C/C++

2011-11-25 07:26:49

冒泡排序,一个经典的算法,重温这一经典算法,却也有种别样的感觉。。。

  1. 1 void bubble(int x[],int n)
    2  {
  2. 3  int temp,j,pass;
  3. 4  int switched=TRUE;
  4. 5  for(pass=0;pass<n-1 && switched==TRUE;pass++){
  5. 6    
  6. 7             /* outer loop controls the number of pass */
  7. 8  switched=FALSE; /* initially no interchanges have been move on this pass */
  8. 9  for(j=0;j<n-pass-1;j++
  9. 10        
  10. 11            /* inner loop governs each individual pass */
  11. 12        
  12. 13  if (x[j]>x[j+1]){
  13. 14            /* elements out of order */
  14. 15            /* an interchange is necessary */
  15. 16  switched=TURE;
  16. 17  temp=x[j];
  17. 18  x[j]=x[j+1];
  18. 19  x[j+1]=temp;
  19. 20   } /* end if */
  20. 21  } /* end for */
  21. 22 } /* end bubble */
阅读(4483) | 评论(0) | 转发(0) |
0

上一篇:Linux内核用到的GCC扩展

下一篇:没有了

给主人留下些什么吧!~~