//
this is a program in<Algorithm design and analysis>,p9
#include < iostream >
using namespace std;
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]);
}
}
}
int main()
{
int a[] = { 3 , 4 , 5 , 6 , 7 };
perm(a, 0 , 4 );
}
#include < iostream >
using namespace std;
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]);
}
}
}
int main()
{
int a[] = { 3 , 4 , 5 , 6 , 7 };
perm(a, 0 , 4 );
}