64,683
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
elemTrype max1(elemTrype a,elemTrype b);
elemTrype max1(vector<elemTrype> a);
int main(void)
{
int arry[5] = {1,6,3,4,5};
vector<int> a(arry,arry+5);
float arryf[5] = {1.1,6.1,3.1,4.1,5.1};
vector<float> af(arryf,arryf+5);
cout << "max1 is :" << max1(a) << endl;
cout << "max1 is :" << max1(af) << endl;
cout << "max1 is :" << max1(2,5) << endl;
cout << "max1 is :" << max1(2.1,2.5) << endl;
return 0;
}
template <typename elemTrype>
elemTrype max1(elemTrype a,elemTrype b)
{
return (a>b ? a : b);
}
template <typename elemTrype>
elemTrype max1(vector<elemTrype> a)
{
return *max_element(a.begin(),a.end());
}