std::min
<algorithm>
template <class T> const T& min ( const T& a, const T& b ); template <class T, class Compare> const T& min ( const T& a, const T& b, Compare comp );
Return the lesser of two arguments
Returns the lesser of
a
and
b
. If both are equivalent,
a
is returned.
The comparison uses operator< for the first version, and comp for the second.
The behavior of this function template is equivalent to:
| |
std::max
<algorithm>
template <class T> const T& max ( const T& a, const T& b ); template <class T, class Compare> const T& max ( const T& a, const T& b, Compare comp );
Return the greater of two arguments
Returns the greater of
a
and
b
. If both are equivalent,
a
is returned.
The comparison uses operator< for the first version, and comp for the second.
The behavior of this function template is equivalent to:
| |
std::min_element
<algorithm>
template <class ForwardIterator> ForwardIterator min_element ( ForwardIterator first, ForwardIterator last ); template <class ForwardIterator, class Compare> ForwardIterator min_element ( ForwardIterator first, ForwardIterator last, Compare comp );
Return smallest element in range
Returns an iterator pointing to the element with the smallest value in the range
[first,last)
. The comparisons are performed using either
operator<
for the first version, or
comp
for the second; An element is the smallest if no other element compares less than it (it may compare equal, though).
The behavior of this function template is equivalent to:
| |
std::max_element
<algorithm>
template <class ForwardIterator> ForwardIterator max_element ( ForwardIterator first, ForwardIterator last ); template <class ForwardIterator, class Compare> ForwardIterator max_element ( ForwardIterator first, ForwardIterator last, Compare comp );
Return largest element in range
Returns an iterator pointing to the element with the largest value in the range
[first,last)
. The comparisons are performed using either
operator<
for the first version, or
comp
for the second; An element is the largest if it does not compare less than any other element (it may compare equal, though).
The behavior of this function template is equivalent to:
| |
std::lexicographical_compare
<algorithm>
template <class InputIterator1, class InputIterator2> bool lexicographical_compare ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2 ); template <class InputIterator1, class InputIterator2, class Compare> bool lexicographical_compare ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp );
Lexicographical less-than comparison
Returns
true
if range
[first1,last1)
compares lexicographically less than the range
[first2,last2)
.
Lexicographical comparison is used for example to sort words alphabetically in dictionaries (or in the list of algorithms right here on the left); It involves comparing sequentially the elements that have the same position in both ranges against each other until one element is not equivalent to the other. The result of comparing these first non-matching elements is the result of the lexicographical comparison.
The behavior of this function template is equivalent to:
| |
std::next_permutation
<algorithm>
template <class BidirectionalIterator> bool next_permutation (BidirectionalIterator first, BidirectionalIterator last ); template <class BidirectionalIterator, class Compare> bool next_permutation (BidirectionalIterator first, BidirectionalIterator last, Compare comp);
Transform range to next permutation
Rearranges the elements in the range [first, last) into the lexicographically next greater permutation of elements. The comparisons of individual elements are performed using either
operator<
for the first version, or
comp
for the second.
A permutation is each one of the N! possible arrangements the elements can take (where N is the number of elements in the range). Different permutations can be ordered according on how they compare lexicographicaly to each other; The first such-sorted possible permutation (the one that would compare lexicographically smaller to all other permutations) is the one which has all its elements sorted in ascending order, and the largest has all its elements sorted in descending order.
If the function can determine the next higher permutation, it rearranges the elements as such and returns true . If that was not possible (because it is already at the largest), it rearranges the elements according to the first permutation (sorted in ascending order) and returns false .
Parameters
-
first, last
- Bidirectional iterators to the initial and final positions of the sequence. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last. comp
- Comparison function object that, taking two values of the same type than those contained in the range, returns true if the first argument is to be considered less than the second argument.
Return value
true if the function could rearrange the object as a lexicographicaly greater permutation. Otherwise, the function returns false to indicate that the arrangement is not greater than the previous, but the lowest possible (sorted in ascending order).Example
| |
Output:
The 3! possible permutations with 3 elements: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 |
std::prev_permutation
<algorithm>
template <class BidirectionalIterator> bool prev_permutation (BidirectionalIterator first, BidirectionalIterator last ); template <class BidirectionalIterator, class Compare> bool prev_permutation (BidirectionalIterator first, BidirectionalIterator last, Compare comp);
Transform range to previous permutation
Rearranges the elements in the range [first, last) into the lexicographically next smaller permutation of elements. The comparisons of individual elements are performed using either
operator<
for the first version, or
comp
for the second.
A permutation is each one of the N! possible arrangements the elements can take (where N is the number of elements in the range). Different permutations can be ordered according on how they compare lexicographicaly to each other; The first such-sorted possible permutation (the one that would compare lexicographically smaller to all other permutations) is the one which has all its elements sorted in ascending order, and the largest has all its elements sorted in descending order.
If the function can determine the previous smaller permutation, it rearranges the elements as such and returns true . If that was not possible (because it is already at the smallest), it rearranges the elements according to the last permutation (sorted in descending order) and returns false .
Parameters
-
first, last
- Bidirectional iterators to the initial and final positions of the sequence. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last. comp
- Comparison function object that, taking two values of the same type than those contained in the range, returns true if the first argument is to be considered less than the second argument.
Return value
true if the function could rearrange the object as a lexicographicaly smaller permutation. Otherwise, the function returns false to indicate that the arrangement is not smaller than the previous, but the largest possible (sorted in descending order).Example
| |
Output:
3 2 1 3 1 2 2 3 1 2 1 3 1 3 2 1 2 3 |