Expand description

permutation

Generate the lexicographically next permutation of a sequence of elements.

Pseudo-code:

  1. Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
  2. Find the largest index l such that a[k] < a[l]. Since k + 1 is such an index, l is well-defined and satisfies k < l.
  3. Swap a[k] with a[l].
  4. Reverse the sequence from a[k + 1] up to end including the final element.

Functions

Generates the lexicographically next permutation of an array / vector.