Or login with:
#include <algorithm> template < class ForwardIterator > ForwardIterator max_element( ForwardIterator first, ForwardIterator last ); template < class ForwardIterator, class BinaryPredicate > ForwardIterator max_element( ForwardIterator first, ForwardIterator last, BinaryPredicate comp );Parameters:
| Parameter | Description |
|---|---|
| first | A forward iterator addressing the position of the first element in the range to be searched for the largest element |
| last | A forward iterator addressing the position one past the final element in the range to be searched for the largest element |
| comp | User-defined predicate function object that defines the sense in which one element is greater than another. The binary predicate takes two arguments and should return true when the first element is less than the second element and false otherwise |
[first, last).
The first version compares objects using operator< and the second compares objects using a function object comp.#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a[] = {2, 6, 10, 8, 4}; vector<int> v(a, a+5); cout <<"\nHere are the integer values in the vector:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nThe maximum value in the vector is "<<*max_element(v.begin(), v.end())<<"."; return 0; }
You must login to leave a messge