#include <cctype>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
vector<int> numbers = {1,2,3};
// 从大到小排序
sort(numbers.begin(),numbers.end(),[](const int & a,const int & b){
return a>b;
});
do
{
for(auto i:numbers){
cout << i++ << " ";
}
cout << endl;
}while(prev_permutation(numbers.begin(),numbers.end()));
cout << "-------------------------------------" << endl;
// 从小到大排序
sort(numbers.begin(),numbers.end());
do
{
for(auto i:numbers){
cout << i++ << " ";
}
cout << endl;
}while(next_permutation(numbers.begin(),numbers.end()));
return 0;
}
输出
3 2 1
3 1 2
2 3 1
2 1 3
1 3 2
1 2 3
-------------------------------------
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
标签:std,排列,const,int,numbers,include
From: https://www.cnblogs.com/Mask2024/p/18091254