Permutations without recursion?

Possible duplicate:
How to find all permutations of a string without using recursion?

Hi, I wrote a program that created all permutations of a given string. I am trying to change it so as not to use recursion when using a queue. I'm not sure how to do this ... any help would be appreciated! Here is my code:

vector<string> generate_substrings(string s) { vector<string> result; if(s.length()==0) result.push_back(s); else { for(int j = 0; j <= s.length(); j++) { cout << s.substr(0,j) << " "; } generate_substrings(s.substr(1,s.length()-1)); } system("Pause"); return result; } int main() { vector<string> result; cout << "Please enter a word: "; string word; cin >> word; generate_substrings(word); cout << endl; return 0; } 
0
source share

Source: https://habr.com/ru/post/1385971/


All Articles