Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

min_element


Algorithm

Summary

Finds the minimum value in a range.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>
template <class ForwardIterator>
 ForwardIterator
 min_element(ForwardIterator first, ForwardIterator last);

template <class ForwardIterator, class Compare>
 InputIterator
 min_element(ForwardIterator first, ForwardIterator last,
             Compare comp);

Description

The min_element algorithm returns an iterator that denotes the minimum element in a sequence. If the sequence contains more than one copy of the minimum element, the iterator points to the first occurrence of the element. In the second version of the function, the optional argument comp defines a comparison function that can be used in place of the default operator<.

Algorithm min_element returns the first iterator i in the range [first, last) such that for any iterator j in the same range, the following corresponding conditions hold:

!(*j < *i)

or

comp(*j, *i) == false.

Complexity

min_element performs exactly max((last - first) - 1, 0) applications of the corresponding comparisons.

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you have to write:

vector<int,allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

max, max_element, min



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998