Why is my code giving no output when I use the if condition inside for loop in permute function. I think the logic is fine.
Code Link: https://ide.codingblocks.com/s/134750
Recursion-Dictionary Order(Larger)
How to write compare function??? and why simple if statement not working ??
I’ve written comparison statement. Still its showing wrong answer in two test cases. Code link: https://ide.codingblocks.com/s/134953
@raj.bmp.333 hey Rishav
bool mycompare(string a,string b){
if(a>b){
return true;
}
return false;
}
void permute(string str,int i,string cpy){
if(str[i]==’\0’){
if(mycompare(str,cpy)){
cout<<str<<endl;
}
return ;
}
for(int j=i;str[j]!=’\0’;j++){
swap(str[i],str[j]);
permute(str,i+1,cpy);
}
}
this will work fine
Why are you using only one swap statement? Don’t we need to again swap in order to backtrack to get all possible permutations?
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.