第1个回答 2010-04-16
方法一:
int max(vector<int> ivec) //与数组相似的方法
{
int temp=0;
for(int i=0;i<ivec.size();i++)
if(temp<ivec[i])
temp=ivec[i];
return temp;
}
方法二:
int max(vector<int> ivec) //使用遍历器的方法
{
int temp=0;
for(vector<int>::iterator it=ivec.begin();it!=ivec.end();it++)
{
if(temp<*it)
temp=*it;
}
return temp;
}