Last active
October 21, 2021 10:18
-
-
Save pradhuman7d1/21afea80b3220195d0c3c1526a1db170 to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/2021 printPermutations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void printPermutations(string str, string asf){ | |
if(str.length() == 0) { // base case | |
cout << asf << endl; | |
return; | |
} | |
for(int i = 0; i < str.length(); i++) { // loop for traversing the string | |
printPermutations(str.substr(0, i) + str.substr(i + 1), asf + str[i]); // recursive call | |
} | |
} | |
int main(){ | |
string str; | |
cin>>str; | |
printPermutations(str,""); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void printPermutations(string str, string asf){ | |
// write your code here | |
} | |
int main(){ | |
string str; | |
cin>>str; | |
printPermutations(str,""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment