59 views
Write a $C$ program to fins all permutations of a string (having at most 6 characters). For example, a string of $3$ characters like $"abc"$ has 6 possible permutations: $”abc", "acb", "bca", "bac", "cab", "cba".$
| 59 views

we can solve it using backtracking

string s;

int permutation(int i , int n){

if(i==n-1)

cout<<s;

else{

for(int j=i;j<n;j++){

swap(s[j], s[i]);

permutation(i+1 , n);

swap(s[j] ,s[i]);

}

}

}
by (103 points)