max_element() , min_element()
Returns an iterator pointing to the largest (or smallest) value within the sequence. An optional third argument allows us to provide an alternative comparison operation.
#include <algorithm>
int mval = max( max( max( max( ivec[4], ivec[3] ),
ivec[2] ),ivec[1] ),ivec[0] );
mval = min( min( min( min( ivec[4], ivec[3] ),
ivec[2] ),ivec[1] ),ivec[0] );
vector<int>::const_iterator iter;
iter = max_element( ivec.begin(), ivec.end() );
iter = min_element( ivec.begin(), ivec.end() );
|