头文件:
#include<algorithm>
函数原型:
bool next_permutation(iterator start, iterator end);
next_permutation函数的返回值是布尔类型
例1:
#include<iostream>#include<algorithm>using namespace std;int main(){ string str="abc"; while(next_permutation(str.begin(),str.end())) cout<<str<<endl; return 0;}输出:
例2:
#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){ vector<int> dp; dp.push_back(1); dp.push_back(2); dp.push_back(3); while(next_permutation(dp.begin(),dp.end())){ cout<<dp[0]<<dp[1]<<dp[2]<<endl; } return 0;}输出:
next_permutation()函数功能是输出所有比当前排列大的排列,顺序是从小到大。
prev_permutation()函数功能是输出所有比当前排列小的排列,顺序是从大到小。
---------------------
作者:小拳头
来源:CSDN
原文:https://blog.csdn.net/xiaoquantouer/article/details/53471348
版权声明:本文为博主原创文章,转载请附上博文链接!