问题描述
- 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 == '') { printf(""%sn"" pStr); } else { for(char* pCh = pBegin; *pCh != ''; ++ 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'''};
permutation(str);
getchar();
return 0;
}
时间: 2024-11-06 12:50:13