next_permutation
それが配置されている要素の全体の一連のために所望される場合、関数が使用されてもよいです。
ブールnext_permutation(第BidirectionlIterator、BidirectionalIterator最後 );
ヘッダアルゴリズムはに含ま
すなわちnext_permutation(関数を呼び出しは)最初、最後)のシーケンスをマークされます次の順列ない次の順列がfalseを返さないであろうがある場合、。それ以外の場合はtrueを返します。
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[4] = { 1,2,3,4 };
do
{
for (int i = 0; i < 4; ++i)
cout << a[i] << ' ';
cout << endl;
} while (next_permutation(a, a + 4));
return 0;
}
高い時間計算:O(N!)、N配列の長さであります