Tricky permutation , some test cases failed

where is my code geting wrong .
my code is https://ide.codingblocks.com/s/105991

Hello @ejazsaifi70,

Your code is not printing in the lexicographical order.
Example:
ABC
Expected Output:
ABC
ACB
BAC
BCA
CAB
CBA
Your Output:
ABC
ACB
BAC
BCA
CBA
CAB

Try to correct this error.
Hope, this would help.
Give a like, if you are satisfied.