find max and min value index in vector c++ code example
Example 1: max of a vector c++
cout<<*max_element(a.begin(), a.end())<<endl;
Example 2: get min and max element index from vector c++
int maxElementIndex = std::max_element(v.begin(),v.end()) - v.begin();
int maxElement = *std::max_element(v.begin(), v.end());
int minElementIndex = std::min_element(v.begin(),v.end()) - v.begin();
int minElement = *std::min_element(v.begin(), v.end());