+ 3

Does anyone know how to implement in C++ the cartesian product of 2 vectors using lists?

I would apreciate a solution or some advice to solve this problem

3rd Feb 2019, 9:25 PM
Razvan Badiloiu (Razvy)
Razvan Badiloiu (Razvy) - avatar
7 Réponses
+ 4
The cartesian product is just combining every element from one list with every element from the other. If your lists are called `as` and `bs`: for(auto a : as){ for(auto b : bs){ result.push_back(make_pair(a,b)); } }
4th Feb 2019, 12:55 AM
Schindlabua
Schindlabua - avatar
+ 1
Well you can use any type of loop or list you want. What I am saying is that it's two loops inside each other, where you run through the vectors. What part of the assignment is giving you trouble?
4th Feb 2019, 11:49 AM
Schindlabua
Schindlabua - avatar
0
Is this c++? I dont think i ve seen this before 😅😅
4th Feb 2019, 6:34 AM
Razvan Badiloiu (Razvy)
Razvan Badiloiu (Razvy) - avatar
0
Combining the 2 vectors into 1 pair using the list
4th Feb 2019, 12:17 PM
Razvan Badiloiu (Razvy)
Razvan Badiloiu (Razvy) - avatar
0
I know that i need 2 loop cycles but the implementing itself its tricky
4th Feb 2019, 12:19 PM
Razvan Badiloiu (Razvy)
Razvan Badiloiu (Razvy) - avatar
4th Feb 2019, 12:28 PM
Razvan Badiloiu (Razvy)
Razvan Badiloiu (Razvy) - avatar
0
This is how i tried to do it
4th Feb 2019, 12:28 PM
Razvan Badiloiu (Razvy)
Razvan Badiloiu (Razvy) - avatar