给出数字1,2,3.打印出所有可能的排列。如:123, 132, 213, 231...
#include <iostream>
using namespace std;
void print(int a[], int begin, int n)
{
if (begin == n)
{
for (int i = 0; i < n; i++)
{
cout << a[i];
}
cout << endl;
}
else
{
for (int i = begin; i < n; i++)
{
swap(a[begin], a[i]);
print(a, begin+1, n);
swap(a[begin], a[i]);
}
}
}
void printAll(int a[], int n)
{
print(a, 0, n);
}
int main()
{
int a[] = {1, 2, 3};
printAll(a, 3);
return 0;
}