Thursday, June 21, 2012

Next Permutation

Documentation : http://www.cplusplus.com/reference/algorithm/next_permutation/
More : http://wordaligned.org/articles/next-permutation

Example :
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
cin>>n;
int * A = new int[n];
for (int i = 0; i < n; i++) A[i] = i + 1;
do {
for (int i = 0; i < n; i++) cout<<A[i]<<" ";
cout<<"\n";
} while (next_permutation(A, A + n)) ;
return 0;
}
view raw next_perm.cpp hosted with ❤ by GitHub

No comments:

Post a Comment