标签:
#include <cstdlib>
#include <iostream>
#define N 4
char array[N]={‘a‘,‘b‘,‘c‘,‘d‘};
using namespace std;
void print()
{
int i;
for(i=0;i<N;i++ )
{
printf("%c ",array[i]);
}
printf("\n");
}
//n 0 i 0 1 2 3
//n 1 i 1 2 3
//n 2 i 2 3
void f(int n)
{
int i =0;
char tmp;
if(n==N-1)
{
print();
return ;
}
for(i=n;i<N;i++)
{
tmp = array[i];
array[i] = array[n];
array[n] = tmp;
f(n+1);
tmp = array[i];
array[i] = array[n];
array[n] = tmp;
}
}
int main(int argc, char *argv[])
{
f(0);
system("PAUSE");
return EXIT_SUCCESS;
}
标签:
原文地址:http://www.cnblogs.com/danjie/p/4243710.html