例如:输入a,b,c,就会输出abc,acb,bac,bca,cab,cba这六种排列方式
#include <stdio.h>
void Permutation(char*a,char*current);
int main()
{
char s[30]="abc";
Permutation(s,s);
return 0;
}
void Permutation(char*a,char*current)
{
if(*current=='\0')
printf("%s\n",a);
for(char*next=current;*next!='\0';next++)
{
char tem=*current;
*current=*next;
*next=tem;
Permutation(a,current+1);
tem=*current;
*current=*next;
*next=tem;
}
}
void Permutation(char*a,char*current);
int main()
{
char s[30]="abc";
Permutation(s,s);
return 0;
}
void Permutation(char*a,char*current)
{
if(*current=='\0')
printf("%s\n",a);
for(char*next=current;*next!='\0';next++)
{
char tem=*current;
*current=*next;
*next=tem;
Permutation(a,current+1);
tem=*current;
*current=*next;
*next=tem;
}
}
我在Vc++6.0中编译有问题啊!
温馨提示:答案为网友推荐,仅供参考