NextPermutation

NextPermutation[p]
gives the permutation following p in lexicographic order.

DetailsDetails