#include <iostream>
using namespace std;
int total = 0;
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void perm(int list[], int k, int m)
{
if(k > m)
{
for(int i = 0; i <= m; i++)
{
cout << list[i] << ' ';
}
cout << endl;
total++;
}
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 (void)
{
int list[] = {1, 2, 3, 4, 5};
perm(list, 0, 4);
cout << total << endl;
return 0;
}
全排列
最新推荐文章于 2024-09-06 22:48:50 发布