#include"iostream"
#include"algorithm"
using namespace std;
int main()
{
//prev_permutation 倒序
int a[3]={3,2,1};
do
{
for(int i=0;i<3;i++)
cout<<a[i]<<" ";
cout<<endl;
}while(prev_permutation(a,a+3));
//输入结果
/*
3 2 1
3 1 2
2 3 1
2 1 3
1 3 2
1 2 3
*/
cout<<endl;
//next_permutation 倒序
int b[3]={1,2,3};
do
{
for(int i=0;i<3;i++)
cout<<b[i]<<" ";
cout<<endl;
}while(next_permutation(b,b+3));
//输入结果
/*
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
*/
}
网友评论