next_permutation()
vrakas (45)
Feb 8, 2013 at 5:19pm UTC
Hello. I want to use next permutation on an array of structs i did depending on an integer variable x. Can i do this?
1 2 3 4
struct my_struct{
int x;
....
};
L B (3817)
Feb 8, 2013 at 5:34pm UTC
I don't understand what exactly it is you want, can you try explaining it more?
vrakas (45)
Feb 9, 2013 at 1:37pm UTC
lets say i have a struct s
1 2 3 4
struct s
{
int a,b;
}
and
1 2 3 4 5 6 7
s arr[3];
arr[0].a=1;
arr[0].b=1;
arr[1].a=2;
arr[0].b=1;
arr[2].a=3;
arr[0].b=1;
i want to do next permutation depending on the int a. (there are6 permutations here).
can i do it?
JLBorges (1756)
Feb 9, 2013 at 2:13pm UTC
1 2 3 4 5 6 7 8 9 10
#include <vector>
int main()
{
struct S { S( int a, int b ) : a(a), b(b) {} int a, b ; } ;
std::vector<S> seq ;
for ( int a : { 1, 2, 3 } ) for ( int b : { 4, 5 } ) seq.emplace_back( a, b ) ;
}