代码:
#include <bits/stdc++.h>
using namespace std;
void Display(int number[],int length) {
for(int i = 0;i < length;i++)
cout<<number[i]<<" ";
cout<<endl;
}
void SearchPermutation(int number[],int length) {
do
{
Display(number,length);
}while(next_permutation(number,number+length));
}
int main()
{
int number[] = {1,2,3,4};
int length = sizeof(number)/sizeof(number[0]);
SearchPermutation(number,length);
return 0;
}
Output:
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1