原帖(C++)地址:http://blog.csdn.net/gaotong2055/article/details/8637745
只是简单的转化而已:
#include<stdio.h>
char *p;
inline void Swap(char *a,char *b)
{
char temp;
temp = *a;
*a = *b;
*b = temp;
}
void Perm(char list[],int start,int end)//Perm(str, 0,3);
{
if(start == end) //即此时集合里只有一个元素
{
for(int i=0; i<=end; i++)
printf("%c",*(p+i));
printf("\n");
}
else
{
for(int i= start; i<= end; i++)
{
Swap(p+start, p+i);//交换可得:1,{2,3,4} ; 2,{1,3,4}; 3,{1,2,4}; 4,{1,2,3}
Perm(p, start+1, end);
Swap(p+start, p+i);//输出排列之后,要再交换回到初始状态:{1,2,3,4}
}
}
}
int main()
{
char str[] = "abcd";
p=str;
Perm(str, 0,3);
return 0;
}
![](https://img-my.csdn.net/uploads/201303/14/1363272453_7637.jpg)