Object-orientation may help you here.
As the first step in that direction, you could make the type of children
to be this:
std::vector<std::pair<std::vector<std::vector<char>>, int>> children;
(The first component of the std::pair<>
is your "2D data"; its second component is the scores.)
As for how to sort this, use the sorting capabilities that the C++ standard library already makes available to your outer std::vector<>
(i.e., std::sort()
). Instead of using its often-used std::less<>
criteria, you would formulate something that knows the format of the std::pair<>
and accesses the score portion of it.
Next, also consider encapsulating that entire std::pair<>
as a user-defined type (i.e., define yourself a class which has both your "2D data" and the scores as data members), and use your newly-defined type in place of this std::pair<>
.
The result is programming that is easier to maintain and work with (including doing manipulations like sorting):
std::vector<YourNewType> children;