//求出所有的排列组合
#include <iostream>
using namespace std;
void swap(int *a,int *b);
void fullLine(int A[],int len,int index);
void fullLine(int A[],int len);
int count =0;
int main(int argc, char** argv) {
int A[9];
A[0]=0;
A[1]=1;
A[2]=2;
A[3]=3;
fullLine(A,4,0);
cout<<"排列总数:"<<count<<endl;
return 0;
}
//输出数组的所有全排列
void fullLine(int A[],int len){
if(A==NULL||len<=0){
return;
}
fullLine(A,len,0);
}
void fullLine(int A[],int len,int index){
if(index == len-1){
for(int i=0;i<len;i++)
cout<<A[i];
cout<<endl;
++count;
}
for(int i =index;i<len;i++){
swap(&A[index],&A[i]);
fullLine(A,len,index+1);
swap(&A[index],&A[i]);
}
}
void swap(int *a,int *b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
输出一个数的全排列
最新推荐文章于 2020-12-15 11:02:33 发布