Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- static int permutations = 0;
- void permute(string src, string permutation){
- if(src.length() == 0){
- cout << permutation << endl;
- permutations++;
- return;
- }
- for(int i = 0; i < src.length(); i++){
- string newSrc = src.substr(0 ,i) + src.substr(i+1, src.length() - (i + 1));
- permute(newSrc, permutation + src[i]);
- }
- }
- void permute(string src){
- permute(src, "");
- }
- int main()
- {
- permute("1234");
- cout << "Number of permutations: " << permutations << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement