Skip to content

Instantly share code, notes, and snippets.

@krisys
Last active September 25, 2015 15:58
Show Gist options
  • Save krisys/946775 to your computer and use it in GitHub Desktop.
Save krisys/946775 to your computer and use it in GitHub Desktop.
Permutation (Recursive)
#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