一、next_permutation
next_permutation是stl按照字典序获取下一个排列的函数,常与vector搭配使用
二、使用步骤
2.1 获取下一个排列
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
vector<int> tmp = {
1, 2, 3};
next_permutation(tmp.begin(), tmp.end());
for (int t : tmp) {
cout << t;
}
cout << endl;
return 0;
}
执行结果:
132
2.2 获取全排列
获取全排列前要对原数据排序,确保当前数据是第一个排列
#

最低0.47元/天 解锁文章
1459

被折叠的 条评论
为什么被折叠?



