Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Latest commit

History

History
19 lines (14 loc) 路 879 Bytes

minmax_element.md

File metadata and controls

19 lines (14 loc) 路 879 Bytes

minmax_element

Description : Returns a pair with an iterator pointing to the element with the smallest value in the range as first element, and the largest as second.

Example:

    std::array<int,5> myarray {3,2,1,5,4}; // define myarray for manipulation

    auto result = std::minmax_element (myarray.begin(),myarray.end());

    std::cout << "min is " << *result.first; // returns the min element from the pair
    std::cout << ", at position " << (result.first-myarray.begin()) << '\n'; // returns the position of the min element
    std::cout << "max is " << *result.second; // returns the max element from the pair
    std::cout << ", at position " << (result.second-myarray.begin()) << '\n'; // returns the position of the max element
  

See Sample code Run Code