How can I create cartesian product of vector of vectors?

First, I’ll show you a recursive version. // Cartesion product of vector of vectors #include <vector> #include <iostream> #include <iterator> // Types to hold vector-of-ints (Vi) and vector-of-vector-of-ints (Vvi) typedef std::vector<int> Vi; typedef std::vector<Vi> Vvi; // Just for the sample — populate the intput data set Vvi build_input() { Vvi vvi; for(int i = 0; … Read more

Generate all combinations from multiple lists

You need recursion: Let’s say all your lists are in lists, which is a list of lists. Let result be the list of your required permutations. You could implement it like this: void generatePermutations(List<List<Character>> lists, List<String> result, int depth, String current) { if (depth == lists.size()) { result.add(current); return; } for (int i = 0; … Read more