Created
August 12, 2013 09:12
-
-
Save ygabo/6209372 to your computer and use it in GitHub Desktop.
Generate all the permutations of a string.
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> | |
void perm(std::string x, int last){ | |
if( last == 0 ){ | |
std::cout << x << std::endl; | |
return; | |
} | |
for( int i = 0; i <=last; i++){ | |
std::swap(x[i], x[last]); | |
perm(x, last-1); | |
std::swap(x[i], x[last]); | |
} | |
} | |
int main(){ | |
std::string x = "abc"; | |
perm(x, x.length()-1); | |
std::cin.get(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment