Last active
September 25, 2015 15:58
-
-
Save krisys/946775 to your computer and use it in GitHub Desktop.
Permutation (Recursive)
This file contains 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> | |
#include<string> | |
using namespace std; | |
string deleteKthCharacter(string str, int k){ | |
return str.erase(k, 1); | |
} | |
void permute( string dest, string source, int len){ | |
if( dest.length() == len){ | |
cout << dest << endl; | |
return; | |
} | |
for(int i=0;i<source.length();i++) | |
permute( dest + source[i], deleteKthCharacter(source, i), len); | |
} | |
int main(){ | |
string str="xyz"; | |
permute("", str, str.length()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment