1*max_element (first_index, last_index);
2ex:- for an array arr of size n
3*max_element(arr, arr + n);
1int main(int argc, char** argv) {
2 int A[4] = {0, 2, 3, 1};
3 const int N = sizeof(A) / sizeof(int);
4
5 cout << "Index of max element: "
6 << distance(A, max_element(A, A + N))
7 << endl;
8
9 return 0;
10}
11
1auto Max1 = *max_element(ForwardIt first, ForwardIt last);
2auto Max2 = *max_element(ForwardIt first, ForwardIt last, Compare comp);
3
4//Example:
5#include <bits/stdc++.h>
6using namespace std;
7main() {
8 vector<int> v{ 3, 1, -14, 1, 5, 9 };
9 int result;
10
11 result = *max_element(v.begin(), v.end());
12 cout << "max element is: " << result << '\n'; // 9
13
14 result = *max_element(v.begin(), v.end(), [](int a, int b) { return abs(a)<abs(b); });
15 cout << "max element (absolute) is: " << result << '\n'; //-14
16}