代码:
#include <iostream>
#include <vector>
using namespace std;
void Permutation(char* pStr, char* pBegin)
{
if ( *pBegin == '\0')
{
cout << pStr << "\t";
}
else
{
for (char* pCh = pBegin; *pCh != '\0'; ++pCh)
{
char temp = *pCh;
*pCh = *pBegin;
*pBegin = temp;
Permutation(pStr, pBegin + 1);
temp = *pCh;
*pCh = *pBegin;
*pBegin = temp;
}
}
}
void Permutation(char* pStr)
{
if (pStr == nullptr)
return;
Permutation(pStr, pStr);
}
int main()
{
char pStr[] = "abc";
Permutation(pStr);
cout << endl;
system("pause");
return 0;
}
测试: