Generate list of all possible permutations of a string

后端 未结 30 2842
故里飘歌
故里飘歌 2020-11-22 15:10

How would I go about generating a list of all possible permutations of a string between x and y characters in length, containing a variable list of characters.

Any l

30条回答
  •  耶瑟儿~
    2020-11-22 15:15

    Recursive solution in C++

    int main (int argc, char * const argv[]) {
            string s = "sarp";
            bool used [4];
            permute(0, "", used, s);
    }
    
    void permute(int level, string permuted, bool used [], string &original) {
        int length = original.length();
    
        if(level == length) { // permutation complete, display
            cout << permuted << endl;
        } else {
            for(int i=0; i

提交回复
热议问题