Let's say I have the following input vectors
vector<string> variables = { "A", "B", "C", "D" };
vector<string> operators = { "+" };
As a result I would like to get all different permutations of operators between these variables. Variables are always on fixed locations - only the operators change.
For previous input vectors I need to have the following output:
A + B + C + D
This is simple as only one operator is available ("+"). But, if I have the following input vectors:
vector<string> variables = { "A", "B", "C", "D" };
vector<string> operators = { "+", "-" };
then the following output would be required:
A + B + C + D
A - B + C + D
A + B - C + D
A + B + C - D
A - B - C + D
A + B - C - D
A - B + C - D
A - B - C - D
Now I have all possible variations of those operators between variables.
So far I wrote the following function
template<class T>
vector<vector<T> > getAllPermutations(vector<T> input) {
vector<vector<T> > res;
do {
vector<T> current_vector;
for (T index : input)
current_vector.push_back(index);
res.push_back(current_vector);
} while (next_permutation(input.begin(), input.end()));
return res;
}
but this only solves part of the problem, as I don't know how to generate proper input vector each time I need to call this function.
How to solve this?
B - A - C + D(or equivalently,- A + B - C + D)?