例如输入字符串abc,则输出由字符a、b、c所能排列出来的所有字符串
abc、acb、bac、bca、cab和cba。
这个题目是剑指offer上面的题目。
很好的考察递归的题目
#include <iostream>
#include<cstdio>
using namespace std;
void getStr(char* pStr, char* pBegin)
{
//如果为null
if(!pStr || !pBegin)
return;
if(*pBegin == '\0')
{
printf("%s\n", pStr);
}
else
{
for(char* pCh = pBegin; *pCh != '\0'; ++ pCh)
{
char temp = *pCh;
*pCh = *pBegin;
*pBegin = temp;
getStr(pStr, pBegin + 1);
temp = *pCh;
*pCh = *pBegin;
*pBegin = temp;
}
}
}
int main()
{
char str[] = "abc";
getStr(str,str);
return 0;
}
http://blog.csdn.net/wuzhekai1985/article/details/6643127
这篇文章也有消息的介绍