Answers for "how to generate all permutations of a string c++"

C++
8

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]);  
        }  
    }  
}
Posted by: Guest on May-01-2020
0

c++ permutation

The 3! possible permutations with 3 elements:
1 2 4
  31 69
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
After loop: 1 2 3
Posted by: Guest on April-06-2022

Code answers related to "how to generate all permutations of a string c++"

Browse Popular Code Answers by Language