Horje
find permutations Code Example
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]);  
        }  
    }  
}  
find permutations
void find_permutations(vector<int> &array, size_t index, vector<int> current_perm, vector<vector<int>> &res){
    if(index == array.size()) 
        res.push_back(current_perm);
    else{
        for(size_t i = 0; i <= current_perm.size(); ++i){
            vector<int> new_perm(current_perm.begin(), current_perm.end());
            new_perm.insert(new_perm.begin()+i, array[index]);
            find_permutations(array, index+1, new_perm, res);
        }
    }
}




Cpp

Related
kmp c++ Code Example kmp c++ Code Example
std::array c++ Code Example std::array c++ Code Example
passing a 2d array cpp Code Example passing a 2d array cpp Code Example
c++ allocate dynamic with initial values Code Example c++ allocate dynamic with initial values Code Example
Python ord() Code Example Python ord() Code Example

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