#include <iostream>
#include <cstring>
using namespace std;
void swap (char *str, int i, int j)
{
char tmp = str[i];
str[i] = str[j];
str[j] = tmp;
}
void fullarrange (char *str, int beg, int nlen)
{
static int cnt = 0;
if ( beg < nlen-1)
{
for (int i=beg; i<nlen; i++)
{
swap(str, beg, i);
fullarrange(str, beg+1, nlen);
swap(str, beg, i);
}
}
else
{
cout<<++cnt<<": "<<str<<endl;
}
}
int main ()
{
char str[16]="abcde";
int nlen = strlen(str);
fullarrange(str, 0, nlen);
return 0;
}
字符串的全排列程序
最新推荐文章于 2021-09-01 10:44:10 发布