2 fasloww fasloww 于 2013.09.21 19:48 提问

C递归求全排列!求解释程序,不懂

#include
#include
void Permutation(char* pStr, char* pBegin);

void permutation(char* pStr)

{

Permutation(pStr, pStr);

}

void Permutation(char* pStr, char* pBegin)

{

if(!pStr || !pBegin)

return;

if(*pBegin == '\0')  
{  
    printf("%s\n", pStr);  
}  
else  
{  
     for(char* pCh = pBegin; *pCh != '\0'; ++ pCh)   
    {  
        // swap pCh and pBegin  
        char temp = *pCh;  
        *pCh = *pBegin;  
        *pBegin = temp;  

        Permutation(pStr, pBegin + 1);    
        // restore pCh and pBegin  
        temp = *pCh;  
        *pCh = *pBegin;  
        *pBegin = temp;  
    }  
}  

}

int main()
{
char str[] ={'a','b','c','d','\0'};
permutation(str);
getchar();
return 0;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!