C语言全排列算法演示
#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]);
        }
    }
}
template < class Type >
inline void Swap(Type& a, Type& b)
{
    Type temp = a;
    a = b;
    b = temp;
}
int main()
{
    int list[] = {1,2,3};
    Perm(list,0,2);
    return 0;
}
