您的位置:首页 > 其它

递归分治解决全排列问题

2011-12-08 16:16 211 查看
#include<iostream>
using namespace std;

template<class Type>
inline void Swap(Type &a,Type &b){
Type temp = a;
a = b;
b = temp;
}
template<class Type>
void Perm(Type list[],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 main(){
int L[3] = {1,2,3};
Perm(L,0,2);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: