/*
28:> 字符串全排列
递归,子问题求解
将首字母和后面每一个字母交换,对处理后的序列做相同处理(str+1)
*/
void perm(char* pStr, char* pBegin);
void perm(char* pStr)
{
if (pStr == NULL)
return;
perm(pStr,pStr);
}
void perm(char* pStr,char* pBegin)
{
if (*pBegin == '\0')
cout << pStr << endl;
else
{
for (char* pCh = pBegin; *pCh != '\0'; ++pCh)
{
std::swap(*pCh,*pBegin);
perm(pStr,pBegin+1);
std::swap(*pCh, *pBegin);
}
}
}
//void test()
//{
// char ar[4] = {'a','b','c'};
// perm(ar);
//}
字符串全排列
最新推荐文章于 2016-09-27 20:48:01 发布