Hello
I could not understand below recursion solution for a combination of upper limit and lower limit point coordinates. How does it progress after print first (1 2 3 4) ? How does ff call stacks work?
Code:
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
// pre: a.size() == b.size()
void ff(const vector<int>& a, const vector<int>& b, vector<int>& c) {
if (c.size() == a.size()) {
for (int x: c) cout << setw(4) << x << ' ';
cout << '\n';
}
else {
c.push_back(a[c.size()]); ff(a, b, c); c.pop_back();
c.push_back(b[c.size()]); ff(a, b, c); c.pop_back();
}
}
void f(const vector<int>& a, const vector<int>& b) {
vector<int> c;
ff(a, b, c);
}
int main() {
vector<int> a{1, 2, 3, 4}, b{10, 20, 30, 40};
f(a, b);