|
prev_permutationfunction template
<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
Return valuetrue 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:
ComplexityAt most, performs one half as many swaps as the number of elements in the range.See also
|