第十四周项目一-排序函数模板
2016-06-20 16:23
141 查看
问题及代码:
运行结果:
知识点总结:
运用了函数模板和冒泡法排序
/* *烟台大学计算机学院 *文件名称:xiangmu3.cpp *作 者:闫安 *完成日期:2016年6月9日 *版 本 号:codeblocks 16.01 * *问题描述:将数组a中的前size个元素按从小到大顺序排列。试设计这个函数模板。 *程序输入:无 *程序输出:运算结果 */ #include<iostream> using namespace std; template<class T> void Sort(T set[],int n) { int i,j; T temp; for(i=0;i<n-1;i++) for(j=0;j<n-1-i;j++) if(set[j]>set[j+1]) { temp=set[j]; set[j]=set[j+1]; set[j+1]=temp; } } int main() { int i; int a[]= {4,0,2,8,6,3}; double b[]= {3.5, 6.7, 2, 5.2, 9.2, 10.3}; Sort(a,6); Sort(b,6); for(i=0; i<6; i++) cout<<a[i]<<" "; cout<<endl; for(i=0; i<6; i++) cout<<b[i]<<" "; cout<<endl; return 0; }
运行结果:
知识点总结:
运用了函数模板和冒泡法排序
相关文章推荐
- sprintf和snprintf用法
- React Native控件之Image组件讲解
- ReactNative安卓首屏白屏优化
- Android 中三种启用线程的方法
- 秦并天下
- leetcode 22. Generate Parentheses
- Linux unlink()
- C#中HttpWebRequest的用法详解
- Android Studio检测内存泄露和性能
- 网页返回的状态码查询表
- bower使用记录
- ansible module
- 琐碎知识点
- ASP.NET Web API(三):安全验证之使用摘要认证(digest authentication)
- art 是怎么把 dalvik 指令编译成 native code 第一篇(雾里看花)
- 二手房过户时七大注意事项
- GUI系统(Graphical User Interface)图形用户界面
- 深入HTTP head的使用详解
- iOS-FMDB和SQLite3使用
- android switch语句报错:case expressions must be constant expressions