(练习)冒泡排序
2014-07-21 19:35
204 查看
/*冒泡排序*/ #include <iostream> using namespace std; #define SIZE 10 void BubbleSort(int value[], int n) { int temp; int flag = 1;//改进:用于判断当没有可交换的数据对时,直接结束排序 int count = 0; for(int i = n-1; i > 0; i--) { for(int j = 0; j < n-1; j++) { if(value[j] > value[j+1]) { temp = value[j]; value[j] = value[j+1]; value[j+1] = temp; flag = 0; } } if(flag == 1) break; count++; flag = 1; } for(i = 0; i < n; i++) { cout<<value[i]<<" "; cout<<endl; } cout<<"遍历数据 "<<count<<" 次"<<endl; } int main() { int value[SIZE]={1,2,3,5,11,22,43,122,22,12}; BubbleSort(value, SIZE); return 0; }
相关文章推荐
- 今天练习了一下用python写函数,就把它记录到博客上吧 冒泡排序和素数判断
- 冒泡排序练习
- 数组以及冒泡排序练习——分数排名题
- 简单排序二--冒泡排序、选择排序、插入排序练习
- 2013年3月算法练习(一)冒泡排序
- 排序算法自我练习(一)——冒泡排序
- 黑马程序员——数组练习(冒泡排序,选择排序)
- Java控制语句和冒泡排序练习
- 冒泡排序,选择排序,4道数组练习
- C语言 关于冒泡排序的过程 练习
- 排序练习:冒泡排序
- 冒泡排序、选择排序、插入排序回顾练习
- C语言数组练习 冒泡排序~
- C语言编程练习——冒泡排序和选择排序
- [算法练习] 冒泡排序
- #小练习 冒泡排序 分类: python 小练习 2013-05-03 14:36 200人阅读 评论(0) 收藏
- [置顶] 算法练习---冒泡排序
- Python练习之-----冒泡排序
- linux程序包管理rpm,yum和编译安装以及冒泡排序练习
- #小练习 冒泡排序