std next permutation

suggest change
template< class Iterator >
bool next_permutation( Iterator first, Iterator last );
template< class Iterator, class Compare >
bool next_permutation( Iterator first, Iterator last, Compare cmpFun );

Effects:

Rearranges the sequence in the range [first, last) into the next lexicographically higher permutation. If cmpFun is provided, the permutation rule is customized.

Parameters:

first — the inclusive beginning of the range to be permuted

last — the exclusive end of the range to be permuted

Return Value:

Returns true if such permutation exists.

Otherwise the range is swapped to the lexicographically smallest permutation and returns false.

Complexity:

O(n), n is the distance from first to last.

Example:

std::vector< int > v { 1, 2, 3 };
do
{
   for( int i = 0; i < v.size(); i += 1 )
   {
       std::cout << v[i];
   }
   std::cout << std::endl;
}while( std::next_permutation( v.begin(), v.end() ) );

print all the permutation cases of 1,2,3 in lexicographically-increasing order.

123
132
213
231
312
321

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents