一,定义
next_permutation的意思是下一个排列,与其相对的是prev_permutation,即上一个排列。
二,用法
next_permutation只能获得下一个排列,如果要获得全排列,那么就需要先对数组进行升序排序
基本定义如下:
next_permutaion(起始地址,末尾地址+1)
next_permutaion(起始地址,末尾地址+1,自定义排序)
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<int> a(n);
sort(a.begin(),a.end());
do{
for(int i = 0; i < a.size(); i++){
cout << a[i] << ' ';
}
cout << endl;
}while(next_permutation(a.begin(),a.end()));//获取下一个排列
}
三,若是结构体,则next_permutation(a,a+n,cmp);