I have two vectors
vector<int> first_v = {1, 4, 9, 16, 8, 56};
vector<int> second_v = {20, 30};
And the goal is to combine those vectors in specific order like that (basically program first prints one value of the first_v vector and then one value of second_v vector):
Expected Output:
1 20 4 30 9 16 8 56
I'm very close to solution but the problem is that if one vector is shorter than another, then program will print '0'.
Problem output:
1 20 4 30 9 0 16 0
Here is the code I tried to solve this problem
merge_vect(first_v, second_v);
vector<int> merge_vect(const vector<int> & a, const vector<int> & b){
vector<int> vec(a.size() + b.size());
for (int i = 0; i < vec.size(); i++){
cout << a[i] << " ";
cout << b[i] << " ";
}
return vec;
}
What can I do in order to solve this problem?