#include
#include
void swap(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
void Permutation(int *pStr, int begin, int end)
{
if(begin == end - 1) //只剩厅历一个元素
{
int i;
for(i = 0; i < end; i++) //打印
printf("%d ", pStr[i]);
printf("\n");
}
else
{
int k;
for(k = begin; k < end; k++)
仿余 {
swap(pStr[k], pStr[begin]); //交换两个字符
Permutation(pStr, begin + 1, end);
备伏滚swap(pStr[k],pStr[begin]); //恢复
}
}
}
int main()
{
int a[] = {1,3,6,7};
Permutation(a, 0, 4);
getchar();
return 0;
}
// it generates all the permutaions of 1,3,6,7
// hope you find my code help, correct me if I am wrong
1111
1113
1133
...
1367
...
6777
7777
void genPerm(char input[], char output[], int len, int num)
{
if(num == len)
{
output[4] = '\0';
cout << output << endl;
return;
}
for(int i = 0; i < len; i++)
{
output[num] = input[i];
genPerm(input, output, len, num+1);
}
}
int main()
{
char a[] = "亩蔽肆贺1367"迅雹州;
char b[5];
doit(a,b,4,0);
return 0;
}