I’ve a vector of vectors say vector<vector<int>> of different sizes as follows:
vector<vector<int>> items = {
{ 1, 2, 3 },
{ 4, 5 },
{ 6, 7, 8 }
};
I want to create combinations in terms of Cartesian product of these vectors like
1,4,6
1,4,7
1,4,8
1,5,6
// ...
3,5,7
3,5,8
How can I do that?
First, I’ll show you a recursive version.
See full code at Compiler Explorer.
Now, I’ll show you the
recursiveiterative version that I shamelessly stole from @John :