print all permutations if number is given for letters code example
Example 1: find all permutations of a string
void permute(string a, int l, int r)
{
// Base case
if (l == r)
cout<<a<<endl;
else
{
// Permutations made
for (int i = l; i <= r; i++)
{
// Swapping done
swap(a[l], a[i]);
// Recursion called
permute(a, l+1, r);
//backtrack
swap(a[l], a[i]);
}
}
}
Example 2: find all permutations of a string
ABC
ACB
BAC
BCA
CBA
CAB