Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find the mminimum of the vector and its position in c++

#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<int> v = {2, 1, 3, 6, 7, 9, 8};
 
    auto it = std::minmax_element(v.begin(), v.end());
    int min_idx = std::distance(v.begin(), it.first);
    int max_idx = std::distance(v.begin(), it.second);
 
    std::cout << min_idx << ", " << max_idx << std::endl; // 1, 5
 
    return 0;
}
 
PREVIOUS NEXT
Tagged: #find #mminimum #vector #position
ADD COMMENT
Topic
Name
3+1 =