I find recursion, apart from very straight forward ones like factorial, very difficult to understand. If i want to print all permutations of a string, well lets say the string length is 5, like "abcde", the permutations of the length 7 should be
abced
abdce
abdec
abecd
abedc
acbde
acbed
acdbe
acdeb
acebd
acedb
adbce
adbec
adcbe
adceb
adebc
adecb
aebcd
aebdc
aecbd
aecdb
aedbc
aedcb
bacde
baced
badce
badec
baecd
baedc
bcade
bcaed
...
If I want a recursion to calculate all permutation of the Factorial of 5, like 4, 3, 2 or 1. Which algorithm should I use? Is there any function in a C++ library for this?
Assume the printout should look like this:
acbd
bcad
abc
bac
ab
ba