Find the Error in the logic of my code

In the question Next Permutation, please tell me the error in my logic.
Here is the code:https://ide.codingblocks.com/s/443406

hey @gaurisha check the output format it has space in between two numbers. Do this.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.