next_permutation(begin,end)

next_permutation(begin,end)

当排列还存在下一种(以字典序排列)排法时,返回true,否则返回false

返回true的同时,把数组变成字典序中的下一种排法。

测试代码:

// Created by CAD on 2020/1/15.
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
int main()
{
    int a[4]={1,2,3};
    do{
        for(int i=0;i<=2;++i)
            cout<<a[i]<<" ";cout<<endl;
    }while(next_permutation(a,a+3));
    return 0;
}

输出:

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
全部评论

相关推荐

10-10 00:14
门头沟学院 Java
程序员小白条:20年架构师,无工资
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务