Tuesday 15 July 2014

c++ - Cartesian product of several vectors -


Similar questions have been asked before but I can not find an exact match for my question.

I have 4 vectors, each of which contains 200-500 4 digits integer. The exact number of elements in each vector varies, but I can fix it for a specific value. I need to find all possible combinations of elements in these 4 vectors.

Example:

v1 [10, 30] v2 [11, 45] v3 [63, 56] v4 [82, 9 8]

Something like this will happen:

[10, 11, 63, 82]; [30, 11, 63, 82]; [10, 45, 63, 82]; [10, 45, 56, 82] etc.

Is there a common name for this algorithm, so can I get its online reference? Otherwise any suggestions for implementing it in C ++ would be useful. Performance is not more of a problem because I need to run the algorithm only once, is anything made in STL?

not much of the algorithm ... <(vector & lt; int & gt; :: constiiterator for i2 = v2.begin (vector & lt; int & gt; :: const_iterator i1 = v1.begin (); i1! = V1.end (); ++ i1);); I2! = V2.end (); ++ i2) for vector const_iterator i3 = v3.begin (); i3! = V3.end (); ++ i3) (vector & lt; int & gt; :: const_iterator i4 = v4.begin (); i4! = V4.end (); ++ i4) COAT & lt; & Lt; "[" & Lt; & Lt; * I1 & lt; & Lt; "," & Lt; & Lt; * I2 & lt; & Lt; "," & Lt; & Lt; * I3 & lt; & Lt; "," & Lt; & Lt; * I4 & lt; & Lt; "]" & Lt; & Lt; Endl;

No comments:

Post a Comment