STL中的全排列next_permutation函数

来源:互联网 发布:王者荣耀淘宝充值 编辑:程序博客网 时间:2024/05/29 15:52
#include <iostream>#include <algorithm>using namespace std;//next_permutation()函数返回的是bool值,排列的范围为[first,last) int main(){int myints[]={1,2,3};sort(myints,myints+3);cout<<"The 3! possible permutations with 3 elements:\n";do{cout<<myints[0]<<" "<<myints[1]<<" "<<myints[2]<<endl; }while(next_permutation(myints,myints+3));   //不要忘记了这个分号 cout<<"*****************************"<<endl;cout<<"After loop:"<<myints[0]<<" "<<myints[1]<<" "<<myints[2]<<endl;return 0;}

0 0
原创粉丝点击