0
点赞
收藏
分享

微信扫一扫

STL--全排列函数

八怪不姓丑 2022-01-16 阅读 38
c++算法

1.函数   std::next_permutation(first, last)

2.用法的前提下是序列在有序的情况下;

#include <algorithm>
#include <string>
#include <iostream>

int main()
{
    std::string s = "abc";
    std::sort(s.begin(), s.end());
    do {
        std::cout << s << '\n';
    } while(std::next_permutation(s.begin(), s.end()));
}
/*
output:
abc
acb
bac
bca
cab
cba
*/
举报

相关推荐

0 条评论