C++ STL全排列
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
int arr[] = {2,1,0};
do
{
cout << arr[0] << ' ' << arr[1] << ' ' << arr[2]<<'\n';
}
while ( prev_permutation(arr,arr+3) );
int arr1[] = {0,1,2};
do
{
cout << arr1[0] << ' ' << arr1[1] << ' ' << arr1[2] <<'\n';
}
while ( next_permutation(arr1,arr1+3) );
return 0;
}
说明:
prev_permutation是获取上一个较大字典序排列,其中3为参数,可根据自己的需求更改。
next_permutation 是获取下一个较大字典序排列,
必要时要对数组先进行排序(sort)