Skip to content

Commit 4803cd4

Browse files
Create permutationRecursion
1 parent 470ce54 commit 4803cd4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

String/permutationRecursion

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Online C++ compiler to run C++ program online
2+
#include <iostream>
3+
using namespace std;
4+
5+
void permute(string str, int l, int r)
6+
{
7+
8+
if (l == r)
9+
cout << str << endl;
10+
else
11+
{
12+
for (int i = l; i <= r; i++)
13+
{
14+
swap(str[l], str[i]);
15+
permute(str, l + 1, r);
16+
swap(str[l], str[i]);
17+
}
18+
}
19+
}
20+
21+
int main() {
22+
int l = 0, r = 2;
23+
permute("abc", l, r);
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)