#include<iostream>
#include<vector>
#include<string>
#include<iterator>
#include<stdlib.h>
#include<time.h>
using namespace std;
template<class T>
class LessThan
{
public:
virtual bool operator()(const T& one,const T& other)=0;
};
template<class T>
class LessThanOfIntDoubleString:public LessThan<T> //针对整数,浮点数和字符串
{
public:
bool operator()(const T& one,const T& other)
{
return one<other;
}
};
template<class T,class Iterator>
void max(const Iterator& beg,const Iterator& end,LessThan<T>& lessthan,T& Maxvalue)
{
Maxvalue=*beg;
Iterator it;
for(it=beg;it!=end;it++)
{
if(*it>Maxvalue) Maxvalue=*it;
}
}
void main()
{
const int n=100;
vector<int>a;
int i;
srand((unsigned)time(0));
for(i=0;i<n;i++)
{
a.push_back(rand()%n);
cout<<a[i]<<" ";
}
cout<<endl;
int Maxvalue;
max(a.begin(),a.end(),LessThanOfIntDoubleString<int>(),Maxvalue);
cout<<"最大值是:"<<Maxvalue<<endl;
}