#include"iostream.h" int str[5]={0,1,2,3,4}; void swap(int &a,int &b); void perm(int list[5],int k,int m) { if(k==m) { for(int i=0;i<m;i++) cout<<list[i]; cout<<endl; } else for(int i=k;i<m;i++) { swap(list[k],list[i]); perm(list,k+1,m); swap(list[k],list[i]); } } void swap(int &a,int &b) { int t=a;a=b,b=t; } void main() { perm(str,0,3); } 运行结果: 012 021 102 120 210 201 Press any key to continue
求排列
最新推荐文章于 2024-09-07 11:05:44 发布