Permutations
std::prev_permutation
and std::next_permutation
return the previous smaller or next bigger permutation of the newly ordered range. If a smaller or bigger permutation is not available, the algorithms return false
. Both algorithms need bidirectional iterators. Per default the predefined sorting criterion std::less
is used. If you use your sorting criterion, it has to obey the strict weak ordering. If not, the program is undefined.
Applies the previous permutation to the range:
Applies the next permutation to the range:
You can easily generate with both algorithms all permutations of the range.