c++ STL 全排列函数的使用

next_permutation(start,end);

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    vector<int> tmp;
    
    tmp.push_back(0);
    tmp.push_back(-1);
    tmp.push_back(1);
    
  
 sort(tmp.begin(),tmp.end());                 //若不排序,则输出结果为全排列中 字典序大于原vector 的部分! 


    do{
        cout<<tmp[0]<<" "<<tmp[1]<<" "<<tmp[2]<<endl;
    }while(next_permutation( tmp.begin() , tmp.end() ) );


    return 0;
}

                                                                                                                                                   ——猪蹄子林泽吟

猜你喜欢

转载自blog.csdn.net/weixin_41988889/article/details/86767117