forked from Yash-Raj-Singh/2nd_sem_oops_files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recursion2.cpp
48 lines (40 loc) · 1.02 KB
/
recursion2.cpp
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
41
42
43
44
45
46
47
48
#include"iostream"
using namespace std;
bool isPallindrome(string str, int l, int r){
if(l>=r) return true;
if(str[l]!=str[r]) return false;
isPallindrome(str, l 1, r-1);
}
int powerSet(string str, int i, string curStr){
if(i==str.length()){
cout<<curStr<<" ";
return 0;
}
powerSet(str, i 1, curStr str[i]);
powerSet(str, i 1, curStr);
}
string swap(string s, int l, int i){
char temp = s[l];
s[l] = s[i];
s[i] = temp;
return s;
}
void permute(string s, int l, int r){
if(l==r){
cout<<s<<" ";
return;
}
for(int i = l; i<=r; i ){
s = swap(s, l, i);
permute(s, l 1, r);
s = swap(s, l, i);
}
}
signed int main(){
string str = "abc";
//cout<<isPallindrome(str, 0, str.size()-1)<<endl;
string curStr = "";
powerSet(str, 0, curStr);
// permute(str, 0, str.size()-1);
return(0);
}