排序函数模板
2016-06-16 17:31
232 查看
/* Copyright (c) 2016* All rights reserved 烟台大学计算机与控制工程学院 * 文件名称:3.cpp * 作者:刘丽 * 完成日期:2016年 6 月 16日 * 版本号: v1.0 【项目-排序函数模板】 已知 void Sort(int a[],int size); void Sort(double a[],int size); 1 2 是一个函数模板的两个实例,其功能是将数组a中的前size个元素按从小到大顺序排列。试设计这个函数模板。 */ #include<iostream> using namespace std; template<class T> void Sort(T a[],int size); int main() { int a[8]={6,5,7,8,9,4,5,6}; double b[5]={1.2,3,6.6,6.7,0.1}; Sort(a,8); Sort(b,5); cout<<"a排序后:"<<endl; for(int i=0;i<8;i++) cout<<a[i]<<" " cout<<endl; cout<<"b排序后:"<<endl; for(i=0;i<5;i++) cout<<b[i]<<" " cout<<endl; return 0; } void Sort(T a[],int size) { T t; for(int i=0;i<size-1;i++) for(int j=i+1;j<size;j++) { t=a[i]; a[i]=a[j]; a[j]=t; } }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android Native 绘图方法
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Mootools 1.2教程 函数
- autoit InputBox 函数
- 文件遍历排序函数
- 关于C#中排序函数的总结
- Oracle 函数大全[字符串函数,数学函数,日期函数]第1/4页
- ASP下经常用的字符串等函数参考资料
- PostgreSQL教程(五):函数和操作符详解(1)
- C#中struct和class的区别详解
- DOS批处理 函数定义与用法
- asp Chr 函数 数字转字母的方法
- Lua中的函数精讲笔记
- Lua中的闭合函数、非全局函数与函数的尾调用详解
- Lua中调用C++函数示例
- Lua实现split函数