Skip to content

Instantly share code, notes, and snippets.

@Onaiplee
Created June 27, 2014 21:47
Show Gist options
  • Save Onaiplee/d6eea5141209887200c4 to your computer and use it in GitHub Desktop.
Save Onaiplee/d6eea5141209887200c4 to your computer and use it in GitHub Desktop.
void permutation(string &s) {
permu_helper(s, 0);
}
void permu_helper(string &s, int level) {
if (level == s.size()) {
cout << s << endl;
return;
}
for (int i = level; i < s.size(); ++i) {
swap(s[level], s[i]);
permu_helper(s, level + 1);
swap(s[level], s[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment