1void permute(string a, int l, int r)
2{
3 // Base case
4 if (l == r)
5 cout<<a<<endl;
6 else
7 {
8 // Permutations made
9 for (int i = l; i <= r; i++)
10 {
11
12 // Swapping done
13 swap(a[l], a[i]);
14
15 // Recursion called
16 permute(a, l+1, r);
17
18 //backtrack
19 swap(a[l], a[i]);
20 }
21 }
22}
1void find_permutations(vector<int> &array, size_t index, vector<int> current_perm, vector<vector<int>> &res){
2 if(index == array.size())
3 res.push_back(current_perm);
4 else{
5 for(size_t i = 0; i <= current_perm.size(); ++i){
6 vector<int> new_perm(current_perm.begin(), current_perm.end());
7 new_perm.insert(new_perm.begin()+i, array[index]);
8 find_permutations(array, index+1, new_perm, res);
9 }
10 }
11}