全排函数c++ next_permutation()

1.函数原型为:

     #include <algorithm>

     bool next_permutation(iterator start,iterator end)

2.用法

(1):需要将要数字按照升序排列

(2):使用方法:

#include<cstdio> 
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a[3]={1,2,3};
    do{
        cout<<a[0]<<a[1]<<a[2]<<endl;
    }while(next_permutation(a,a+3));
    return 0;
}

运行结果:

 

posted @ 2020-05-31 14:52  miao-xixixi  阅读(161)  评论(0编辑  收藏  举报