min_element
Returns the element with the smallest value
Definition
The min_element() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class ForwardIterator >
ForwardIterator min_element(
ForwardIterator first,
ForwardIterator last
);
template < class ForwardIterator, class BinaryPredicate >
ForwardIterator min_element(
ForwardIterator first,
ForwardIterator last,
BinaryPredicate comp
);Parameters:
| Parameter | Description |
| first | A forward iterator addressing the position of the first element in the range to be searched for the smallest element |
| last | A forward iterator addressing the position one past the final element in the range to be searched for the smallest element |
| comp | User-defined predicate function object that defines the sense in which one element is greater than another. The binary predicate takes two arguments and should return true when the first element is less than the second element and false otherwise |
Description
Min_element finds the smallest element in the range [first, last).
The first version compares objects using operator< and the second compares objects using a function object comp.
Return Value
Returns the lowest element in the range [first, last).
Complexity
The complexity is linear; performs exactly (last - first) - 1 comparisons.
CodeCogs®