The nextperm takes as argument a permutation. nextperm returns the next permutation in lexicographic order, or undef if there is no next permutation. Input:
Output: