c++ permutation

Hi all,

I am new to c++. But worked on python. Need to convert the python code snippet to c++. How to simulate the python permutation in c++. Where can find the document for this?

Suggestions are appreciated.

Thank you,
Shruthi LS
Take a look at the reference section of this site. See:

http://www.cplusplus.com/reference/algorithm/next_permutation/
you want to find all array permutations ? or just next permution ?
Python:
1
2
3
4
5
6
import itertools
for L in itertools.permutations( [ 1, 2, 3 ] ):
   print( L )
(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)




C++
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
   int L[] = { 1, 2, 3 };
   do
   {
      for ( auto e : L ) cout << e << ' ';
      cout << '\n';
   } while( next_permutation( L, L + sizeof L / sizeof L[0] ) );
}
1 2 3 
1 3 2 
2 1 3 
2 3 1 
3 1 2 
3 2 1
Thanks a lot for your replies. It had really helped me a lot.
Topic archived. No new replies allowed.