您的位置:首页 > 其它

字符串的全排列 递归

2016-03-11 16:36 351 查看
/*
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: