I'd hate to just give the answer away, but Google is your friend.

Wikipedia: Generate Permutations in Lexicographic Order (the page also has other possible ways to generate permutations). Feel free to ignore this and follow jps's advice if you want to solve the problem for yourself.

Complexity is not an issue. I can easily let this program run for ages. Correctness is essential though, so it can be as slow and chunky as it needs so long as it works.

Be careful what you wish for

There are algorithms which won't finish executing before the predicted heat death of the universe.

What is the original problem you want to solve?