Horje
permutation in c++ with backtracking Code Example
permutation in c++ with backtracking
// C++ program to print all
// permutations with duplicates allowed
#include <bits/stdc++.h>
using namespace std;
 
 
// Function to print permutations of string
// This function takes three parameters:
// 1. String
// 2. Starting index of the string
// 3. Ending index of the 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]);
        }
    }
}
 
// Driver Code
int main()
{
    string str = "ABC";
    int n = str.size();
    permute(str, 0, n-1);
    return 0;
}
 
// This is code is contributed by rathbhupendra




Cpp

Related
Redragon m609 weight Code Example Redragon m609 weight Code Example
OpenCV" is considered to be NOT FOUND Code Example OpenCV" is considered to be NOT FOUND Code Example
what is stdarg.h used for Code Example what is stdarg.h used for Code Example
Pawri Meme codechef solution in c++ Code Example Pawri Meme codechef solution in c++ Code Example
vector init c++ Code Example vector init c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
15