两种不同写法取最小数组元素
2011-04-14 10:39
183 查看
// o414.cpp : Defines the entry point for the console application. // #include "stdafx.h" using namespace std; template <class Type,int size> Type getMin(Type (&array)[size]) { Type minVal = array[0]; for (int i=0;i<size;i++) { if (array[i]<minVal) { minVal = array[i]; } } return minVal; } template <class Type> Type getMin2(Type *array,int size) { Type minVal = array[0]; for (int i=0;i<size;i++) { if (array[i]<minVal) { minVal = array[i]; } } return minVal; } template <class Type> Type getMin3(const Type *array,int size) { Type minVal = array[0]; for (int i=0;i<size;i++) { if (array[i]<minVal) { minVal = array[i]; } } return minVal; } template <class Type> Type myMax(Type a,Type b) { return a>b?a:b; } int _tmain(int argc, _TCHAR* argv[]) { double myd[] = {0.3,1,2,2.2,4,8}; cout<<getMin(myd)<<endl; cout<<getMin2(myd,sizeof(myd)/sizeof(double))<<endl; cout<<getMin3(myd,sizeof(myd)/sizeof(double))<<endl; //cout<<myMax(3,8)<<endl; system("pause"); return 0; }
相关文章推荐
- 多个按钮Button实现的两种不同写法
- laszlo方法的两种不同写法
- Rust: map中的问题,两种写法有什么不同?
- 关于gcd的函数和过程两种不同写法
- C#linq和lamda两种写法返回的集合中的对象元素引用情况不同,循环计算值要小心
- ado:SqlDataAdapter的两种不同写法,以及SqlCommand的两种不同写法
- 两种不同写法的ajax请求数据
- bootstrap两种按钮写法 button 和 a, 可用于表单提交和a不同按钮链接跳转
- 最小生成树--两种常见的写法;
- 我想知道这两种写法的不同,哪个是可以通过,为什么??
- HDU 2609 How many(最小表示法+set判重两种写法)
- vue-cli快速构建的反向代理(新版和旧版的两种不同的写法)
- 静态库和动态库的两种不同的Makefile写法
- 两种浏览器事件的不同写法……
- 两种写法不同作用相同的存储过程
- hibernaet创建SessionFactory不同版本不同写法
- FTP的ASCII和Binary两种传输方式有何不同
- 堆和栈的区别-两种不同的数据结构
- 折半查找的两种写法
- clear-fix清除浮动的两种写法