c++中next_permutation的使用

#include<iostream>
#include<algorithm>
using namespace std;
main()
{
    int i,j=0;
    int a[5]={1,2,3,4,5};
    do
    {
        for(i=0;i<5;i++){
            cout <<a[i]<<" ";
        }
        cout <<endl;
    }while(next_permutation(a,a+5));
}

结果输出a[5]数组的全排列

使用规则:

1.需要引用algorithm

2.next_permutation(需要排列的数组开始的地方,需要排列的数组结束的地方)

posted @ 2018-12-05 15:17  vincand  阅读(269)  评论(0)    收藏  举报