话不多说,代码如下:
代码语言:javascript复制#include<iostream>
using namespace std;
inline void Swap(int &a, int &b)
{
int temp = a;
a = b;;
b = temp;
}
void Perm(int list[], int begin, int end)
{
if (begin == end)
{
for (int i = 0; i <= end; i )
{
cout << list[i];
}
cout << endl;
}
else
{
for (int i = begin; i <= end; i )
{
Swap(list[begin], list[i]);
Perm(list, begin 1, end);
Swap(list[begin], list[i]);
}
}
}
int main()
{
int arr[3] = { 1, 2, 3 };
Perm(arr, 0, 2);
return 0;
}