Johnson trotter algorithm gives a non recursive approach to generate permutations. The algorithm goes something like this..
I'm using a character flag to maintain the direction of the mobile integers.. the code is simple, suggestions to make it more simple are always welcome 😊