posts - 1,  comments - 0,  trackbacks - 0
 1 #include <iostream>
 2 #include <string>
 3 #include <algorithm>
 4 using namespace std;
 5  
 6 void bubbleSort(int *ary,size_t size){
 7     bool flag=true;
 8     for(size_t i=0;i<size;i++){
 9         for(size_t j=0;j<size-i-1;j++){
10             if(ary[j]>ary[j+1]){
11                 swap(ary[j],ary[j+1]);
12                 flag=false;
13             }
14         }
15         if(flag==true)
16             break;
17         flag=true;
18     }
19 }
20  
21  
22 int main(){
23     int test[8]={1,2,3,4,5,6,7,8};
24     bubbleSort(test,8);
25     copy(test,test+8,ostream_iterator<int>(cout," "));
26     system("pause");
27 }
posted on 2009-12-06 20:35 njupt_henry 阅读(137) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理


<2026年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿

随笔档案

搜索

  •  

最新评论