冒泡排序
2016-08-18 21:37
246 查看
不多说,来自学长的挑战。
/************************* *Bubble Sort * * by:ZCB* *************************/ #include<stdio.h> #include<stdlib.h> int main(void) { int a[100]; int b = 0; int c = 1; int d = 0; int i = 0; printf("请输入要排序的数字.\n"); printf("每输入一个数字请按Enter键确认.\n"); printf("输入完毕后请输入0再按Enter键确认.\n"); do { scanf("%d",&a[i]); i++; } while(a[i - 1] != 0); while(c != 0) { b = 0; c = 0; while(b < i - 2) { if(a[b] > a[b + 1]) { int temp = a[b]; a[b] = a[b + 1]; a[b + 1] = temp; c++; } b++; } } printf("排序如下:\n"); for(;d < i - 1;d++) { printf("%d\n",a[d]); } system("pause"); return 0; }
相关文章推荐
- 数据结构之图---最小生成树Prim算法---C++实现
- Boost中的锁
- DetachedCriteria和criteria使用方法及其区别!
- Matlab fsolve 传递参数
- 序列化和反序列化
- 矩阵翻转
- 刺激(codevs 1958)
- 3079. 【备战NOIP2012图论专项模拟试题】砍树 (Standard IO)
- KMP算法学习&总结
- nginx支持websocket
- Round Numbers--杨辉三角,组合数学
- boost封装函数指针
- 设计模式之观察者模式
- 暑假集训 8.18 数据结构实验之图论六:村村通公路 (最小生成树)
- 百度富文本框编辑器不能上传图片
- NVL,NVL2
- xposed模块开发步骤总结
- 简述Java内存泄露
- 虚函数和纯虚函数的区别
- cloudera hadoop 配置文件位置