求教:关于两个参数的全排列算法

[复制链接]
查看11 | 回复6 | 2021-1-27 06:56:28 | 显示全部楼层 |阅读模式
voidf(char*toSolve,intn);
请问这样两个参数能实现全排列算法吗
输入toSolve="abc",n=3;
输出
abc
acb
bac
bca
cab
cba
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:56:28 | 显示全部楼层

回复

使用道具 举报

千问 | 2021-1-27 06:56:28 | 显示全部楼层
/*谁帮忙改改这个程序*/
#include
#include
#include
voidswap(int*a,int*b)
{
intt=*a;
*a=*b;
*b=t;
}
voidf(int*tosolve,intn)
{
staticintcount=1;
if(n==1)
{
printf("%d",*tosolve);
return;
}
for(inti=0;i
#include//没用到它噢
#include//它也没用
#include
voidswap(int*a,int*b)
{
intt=*a;
*a=*b;
*b=t;
}
voidf(int*tosolve,intn)
{
staticintcount=1;
if(n==1)
{
printf("%d",*tosolve);
return;
}
for(inti=0;i
回复

使用道具 举报

千问 | 2021-1-27 06:56:28 | 显示全部楼层
upLS
回复

使用道具 举报

千问 | 2021-1-27 06:56:28 | 显示全部楼层
http://blog.csdn.net/hityct1/archive/2008/08/04/2767198.aspx
回复

使用道具 举报

千问 | 2021-1-27 06:56:28 | 显示全部楼层
#include
#include
#include
#include
#defineN9
usingnamespacestd;
voidprint(char*s,intn)
{
inta[n];
for(inti=0;i(cout,""));
cout
回复

使用道具 举报

千问 | 2021-1-27 06:56:28 | 显示全部楼层
#include
inlinevoidSwap(char&a,char&b)
{
chartemp=a;
a=b;
b=temp;
}
voidPerm(charlist[],intk,intm)
{//生成list[k:m]的所有排列方式
inti;
if(k==m){//输出一个排列方式
for(i=0;i
#include
voidswap(int*a,int*b)
{
intt=*a;
*a=*b;
*b=t;
}
voidf(int*tosolve,intn)
{
staticintcount=1;
if(n==3)
{
printf("%d",*tosolve);
return;
}
for(inti=0;i<n;i++)
{
swap(*tosolve,*(tosolve+i));
printf("%d",*tosolve);
f(tosolve+1,n-1);
swap(*tosolve,*(tosolve+i));
}
}

intmain()
{
inttosolve[3]={1,2,3};
f(tosolve,3);
return0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行