#include<iostream.h>
#include<string.h>
template<class T>
void perm(T list[],int k,int m)
{
int i;
if (k==m)
{
for(i=0;i<=m;i++)
cout<<list[i];
cout<<endl;
}
else
for(i=k;i<=m;i++)
{
swap(list[k],list[i]);
perm(list,k+1,m);
swap(list[k],list[i]);
}
}
template<class T>
swap(T &a,T &b)
{
T temp;
temp=a;a=b;b=temp;
}
void main()
{
int num[]={1,2,3,4,5};
perm(num,0,4);
}
求数组中k到m的元素的全排列。vc6调试通过。