您的位置:首页 > 其它

字符串全排列

2016-09-08 17:28 169 查看
#include <iostream>
using namespace std;

void Permutation_o(char* pStr, char* pBegin)
{
if (*pBegin == '\0' )
{
cout << pStr <<endl;
}
else
{
for (char* pCh = pBegin; *pCh!='\0'; pCh++)
{
char temp = *pCh;
*pCh = *pBegin;
*pBegin = temp;

Permutation_o(pStr, pBegin+1);
//下面是最后一个步骤 你要把排乱的数组给放回去

temp = *pCh;
*pCh = *pBegin;
*pBegin = temp;
}
}
}

void Permutation_o(char* pStr)
{
if (pStr==NULL)
return;
Permutation_o(pStr,pStr);
}

int main(void)
{
char str[10]="abc";
Permutation_o(str);
//cout << str <<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: