(C++) std::min\_element
January 8, 2018 · View on GitHub
(C++) std::min_element
std::min_element is an STL algorithm to find the lowest value in a container.
#include <algorithm> #include <cassert> #include <vector> int main() { //Create a std::vector with values std::vector<int> v; v.push_back( 1); v.push_back( 4); v.push_back( 9); v.push_back(16); v.push_back(25); //Just shuffle for fun std::random_shuffle(v.begin(),v.end()); //Assume the lowest and heighest values are found assert( *std::min_element(v.begin(),v.end()) == 1); assert( *std::max_element(v.begin(),v.end()) == 25); }