to remove the repeating permutations i took a string variable test which stores the s string so as to if the previous value of s is equal to current value of s then the base case will not print the value of s and only return. but i noticed that my test variable become null everytime i dont know how. i have made 2 cout statements for the test value so as to keep the track of it.
Permutation are getting repeated
refer 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.
i want to know whats the problem with my code . why is the test string becoming null everytime even though i am updating it when we reach the base case.
can u explain what exactly are u trying to do?? I think Prateek bhaiya has explained how to find permutations very well in a video
basically what i am trying to do is i am storing the input string “s” value in another string called “output”. I took a third string called “test” initialised as null and reason for taking “test” string is so that i can check if the output string which i am printing is not same as the previous one . I have commented out my logic in the code https://ide.codingblocks.com/s/580631. The only problem is the “test” string is automatically getting null value after the statement return and not saving the output string “s” in it .
even if u pass test and s by reference ur code is not correct.
check for this output aaba
to avoid that only i have used “test” string so that after it prints the first permutation of aaba i.e. abaa “test” stores abaa value and in the next base case we check if abaa is printed or not before but “test” is not working as it forgets the value abaa and becomes null.
“test” string stores the value of “s” in base case but as soon as base case encounters return the value stored in “test” is lost and becomes null. So is call by reference working correctly or not.
i tried ruuning ur code. for sample test its working fine.
check for this output aaba its giving wrong o/p
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.