Suppose I have an array of integers int a[] = {0, 1, ... N-1}, where N is the size of a. Now I need to generate all permutations of
int a[] = {0, 1, ... N-1}
N
a
If you have access to C++ STL, use next_permutation, and do an additional check of a[i] != i in a do-while loop.
do-while