template<class BidIt>
bool prev_permutation(BidIt first, BidIt last);
template<class BidIt, class Pred>
bool prev_permutation(BidIt first, BidIt last, Pred pr);
The first template function determines a repeating sequence of permutations, whose initial permutation occurs when the
sequence designated by iterators in the range [first, last)
is the reverse of one ordered by operator<
. (The
elements are sorted in descending order.) It then reorders the elements in the sequence, by evaluating swap
(X, Y)
for
the elements X
and Y
zero or more times, to form the next permutation. The function returns true only if the resulting
sequence is not the initial permutation. Otherwise, the resultant sequence is the one next smaller lexicographically than
the original sequence. No two elements may have equivalent ordering.
The function evaluates swap(X, Y)
(last - first) / 2
times, at most.
The second template function behaves the same, except that it replaces operator<(X, Y)
with pr(X, Y)
.
See the related sample program.