next_permutation
When it is desired for a whole series of elements are arranged, the function may be used.
bool next_permutation (BidirectionlIterator first, BidirectionalIterator last );
included in the header algorithm
calls the function i.e. next_permutation () will get marked the [first, last) sequence next permutations , if there is no next permutations will return false; otherwise, it returns 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;
}
High time complexity: O (! N), n is the length of the array