[Solved] i’m unable to understand how this code works [closed]


Perhaps you have problem understanding the backtrack technique. In this case you should read a little about it: http://en.wikipedia.org/wiki/Backtracking

However the code works from the char at position 0 up to 2 following chars.
It changes the first char with the folowing, and calls itself with the next char as starting point. Finally switch back the chars to recreate the orign situation.

At the first level of recursion the function is switching the first letter and call itself for the next two:

permute("ABC", 1, 2)
permute("BAC", 1, 2)
permute("CBA", 1, 2)

second level of recursion:

permute("ABC", 2, 2) /* -> printf ABC */
permute("ACB", 2, 2) /* -> printf ACB */

permute("BAC", 2, 2) /* -> printf BAC */
permute("BCA", 2, 2) /* -> printf BCA */

permute("CBA", 2, 2) /* -> printf CBA */
permute("CAB", 2, 2) /* -> printf CAB */

solved i’m unable to understand how this code works [closed]