/*
description:
字符串的全排列
来自<<编程之法>>
author: JasonZhou
date: 2016-03-11
*/
#include <iostream>
using namespace std;
static int count=0;
//递归方法
void CallAllPermutation(char* perm,int from,int to)
{
if (to<1)
{
return;
}
if (from==to)
{
cout<<++count<<":\t";
for (int i=0;i<=to;i++)
{
cout<<perm[i];
}
cout<<endl;
}
else
{
for (int j=from;j<=to;j++)
{
swap(perm[j],perm[from]);
CallAllPermutation(perm,from+1,to);
swap(perm[j],perm[from]);
}
}
}
int main(int argc,char * argv[])
{
char s1[]="abcd";
CallAllPermutation(s1,0,3);
return 0;
}
字符串的全排列 递归
最新推荐文章于 2021-02-17 00:15:45 发布