Given a string, your task is to generate all different strings that can be created using its characters. code example
Example 1: find all permutations of a string
void permute(string a, int l, int r)
{
if (l == r)
cout<<a<<endl;
else
{
for (int i = l; i <= r; i++)
{
swap(a[l], a[i]);
permute(a, l+1, r);
swap(a[l], a[i]);
}
}
}
Example 2: how to print all permutations of a string
void permutation(string s)
{
sort(s.begin(),s.end());
do{
cout << s << " ";
}
while(next_permutation(s.begin(),s.end());
cout << endl;
}