在C语言编译器中如何实现:输入一个字符串,打印出该字符串中字符的所有排列。

例如:输入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;
}
}


追问

我在Vc++6.0中编译有问题啊!

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网