get index of max element of vector c++ code example
Example 1: max element in vector c++
auto max = *max_element(vector.begin(), vector.end());
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());