forked from CodeToExpress/dailycodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallPermutation.cpp
More file actions
40 lines (30 loc) · 731 Bytes
/
allPermutation.cpp
File metadata and controls
40 lines (30 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* @author : imkaka
* @date : 2/1/2019
*/
#include <bits/stdc++.h>
using namespace std;
// Rotation will help us to rearange the chars.
void allPermutation(string str, string out)
{
if (str.size() == 0)
{
cout << out << endl;
return;
}
for (int i = 0; i < str.size(); i++)
{
// Remove first character from str and
// add it to out
allPermutation(str.substr(1), out + str[0]);
// Rotate string in a way second character
// moves to the beginning.
rotate(str.begin(), str.begin() + 1, str.end());
}
}
int main(){
allPermutation("abcde", "");
allPermutation("1234", "");
allPermutation("beyounic", "");
return 0;
}