#include <iostream>
using namespace std;
int x[20],n;
void afis()
{
for (int i = 1; i <= n; i++) cout<<x[i]<<" ";
cout<<endl;
}
void inter(int &x, int &y)
{
int aux=x; x=y; y=aux;
}
void perm(int k, int n)
{
for (int i = k; i <= n; i++)
{
inter(x[k], x[i]);
if(k==n) afis();
else perm(k+1, n);
inter(x[k], x[i]);
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>x[i];
perm(1,n);
return 0;
}
|