Skip to content

Instantly share code, notes, and snippets.

@pradhuman7d1
Last active October 21, 2021 10:18
Show Gist options
  • Save pradhuman7d1/21afea80b3220195d0c3c1526a1db170 to your computer and use it in GitHub Desktop.
Save pradhuman7d1/21afea80b3220195d0c3c1526a1db170 to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/2021 printPermutations
#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,"");
}
#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