输入一个字符串,打印出该字符串中字符的所有排列。
void Permutation(char *pStr,char* pBegin)
{if(*pBegin == '\0')
{
printf("%s\n",pStr);
}
else
{
for(char*pCh=pBegin;*pCh != '\0';++pCh)
{
//交换第一个元素
*pCh = *pBegin;
*pBegin = temp;
Permutation(pStr,pBegin+1);
temp = *pCh;
*pCh = *pBegin;
*pBegin = temp;
}
}
}
void Permutation(char *pStr)
{
if(pStr == NULL)
return;
Permutation(pStr,pStr);
}
void Test(char* pStr)
{
if(pStr == NULL)
printf("Test for NULL begins:\n");
else
printf("Test for %s begins:\n", pStr);
Permutation(pStr);
printf("\n");
}
int main()
{
Test(NULL);
char string1[] = "";
Test(string1);
char string2[] = "a";
Test(string2);
char string3[] = "ab";
Test(string3);
char string4[] = "abc";
Test(string4);
return 0;
}
还未能理解程序逻辑