Expand description
§permutation
Generate the lexicographically next permutation of a sequence of elements.
Pseudo-code:
- Find the largest index
ksuch thata[k] < a[k + 1]. If no such index exists, the permutation is the last permutation. - Find the largest index
lsuch thata[k] < a[l]. Sincek + 1is such an index,lis well-defined and satisfiesk < l. - Swap
a[k]witha[l]. - Reverse the sequence from
a[k + 1]up to end including the final element.
Functions§
- lexicographically_
next_ permutation - Generates the lexicographically next permutation of an array / vector.