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:

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

Parameters:

first- the beginning of the range to be permutated, inclusive

last - the end of the range to be permutated, exclusive

Return Value:

Returns true if such permutation exists.

Otherwise the range is swaped to the lexicographically smallest permutation and return 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.

output:

123  
132
213
231
312
321

Feedback about page:

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


Standard library algorithms:
* std next permutation

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
85 Standard library algorithms
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype