Javatpoint Logo
Javatpoint Logo

std::minmax() and std::minmax_element() in C++ STL

We are already aware that the C++ programming language has a Standard Template Library which is vast like an ocean and has many pre-defined functionalities. To get the answer of which among the array elements passed either as an input by the user or pre-defined by the testers/developers is maximum or minimum amongst them, we use the standard minimum function or the entire function.

It might get a little overwriting or using the code, again and again, to know both values at a time. So C++ STL has a solution for us in the form of std minmax() and minmax_element functions. Both functions accept parameters in the form either variables, which are of any natural numbers, integers and also an array of elements.

C++ Code for minmax() Function

Output:

/ tmp / 1Lj mBg VyK h.o
The minimum value is : 33
The maximum value is : 63
minimum value : 11
maximum value  : 16

C++ Code for minmax_element() Function

Output:

/ tmp /1 LjmB gVy Kh.o
position of the minimum value obtained after operating is : 7
position of the maximum value received after working is : 10

position of the minimum value obtained after operating is : 1
position of the maximum value received after working is : 5






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA