mardi 20 octobre 2020

Generating all possible permutations; Process finished with exit code 11 [duplicate]

I want to generate all possible permutations from a given alphabet, So I wrote the following code:

void generate(char alphabet[],int num_of_alphbet,char* word,int index, int full_lengh)
{
    if (index==full_lengh)
    {
        cout << word << endl;
    }

    for (int i=0;i<num_of_alphbet;i++)
    {
        char tmp=alphabet[i];
        word[index]=alphabet[i];
        generate(alphabet,num_of_alphbet,word,index+1,full_lengh);
        word[index]=tmp;
    }
}

and I call it like this:

int main() {

    char alphabet[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
            ,'0','1','2','3','4','5','6','7','8','9','_','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    char* tmp_word[10];
    generate(alphabet, 7, reinterpret_cast<char *>(tmp_word), 0, 3);
    return 0;
}

But, I am getting the following error and I don't know why/how to fix it:

aaa

Process finished with exit code 11

Aucun commentaire:

Enregistrer un commentaire