全排列函数 next_permutation && prev-permutation

来源:互联网 发布:找字体软件 编辑:程序博客网 时间:2024/05/24 05:28
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){int a[10]={1,2,3};do{  cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;                            }while(next_permutation(a,a+3));cout<<endl<<"--------"<<endl<<endl; int  aa[10]={3,2,1};do{  cout<<aa[0]<<" "<<aa[1]<<" "<<aa[2]<<endl;                            }while(prev_permutation(aa,aa+3)); system("pause"); return 0;} 

 

小结:next_permutation是要在升序数组的条件下输出升序排列,prev-permutation则刚好相反
执行结果: