Next : Generalized Numeric Operations, Previous : Lexicographical comparison, Top : Table of  Contents


Permutation generators

bool next_permutation (BidirectionalIterator first, BidirectionalIterator last) Function
bool next_permutation (BidirectionalIterator first, BidirectionalIterator last, Compare comp) Function

template 
bool next_permutation(BidirectionalIterator first, BidirectionalIterator last);

template 
bool next_permutation(BidirectionalIterator first, BidirectionalIterator last,
                      Compare comp);

next_permutation takes a sequence defined by the range [first, last) and transforms it into the next permutation. The next permutation is found by assuming that the set of all permutations is lexicographically sorted with respect to operator< or comp. If such a permutation exists, it returns true. Otherwise, it transforms the sequence into the smallest permutation, that is, the one sorted in ascending order, and returns false. At most (last - first)/2 swaps are performed.

bool prev_permutation (BidirectionalIterator first, BidirectionalIterator last) Function
bool prev_permutation (BidirectionalIterator first, BidirectionalIterator last, Compare comp) Function

template 

bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last);

template 

bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last,
                      Compare comp);

prev_permutation takes a sequence defined by the range [first, last) and transforms it into the previous permutation. The previous permutation is found by assuming that the set of all permutations is lexicographically sorted with respect to operator< or comp. If such a permutation exists, it returns true. Otherwise, it transforms the sequence into the largest permutation, that is, the one sorted in descending order,, and returns false. At most (last - first)/2 swaps are performed.


 

Top