输出数组的所有排列组合项
#include <iostream>
using namespace std;
#include <algorithm>
static int allNumber = 0;
template<typename T>
void Perm ( T list[],int k ,int m )
{
if ( k == m )
{
for ( int i = 0 ; i <= m ; i++ )
{
cout << list[i]<< " ";
}
allNumber ++;
cout <<endl;
}
else
{
for ( int j = k ; j<= m ; j ++ )
{
swap(list[k],list[j]);
Perm(list,k+1,m);
swap(list[j],list[k]);
}
}
}
int main(int argc, char const *argv[])
{
int array[] = {1,2,3,4,5};
Perm(array,0,4);
cout << allNumber<<endl;
return 0;
}