Respuesta :
Answer:
A C++ program was used in writing a function in merging ( vector a, vector b) or that will merge the two vectors into one new one and return the merged vector.
Explanation:
Solution
THE CODE:
#include <iostream>
#include <vector>
using namespace std;
vector<int> merge(vector<int> a, vector<int> b) {
vector<int> vec;
int i = 0, j = 0;
while(i < a.size() || j < b.size()) {
if(i >= a.size() || (j < b.size() && b[j] < a[i])) {
if(vec.empty() || vec[vec.size()-1] != b[j])
vec.push_back(b[j]);
j++;
} else {
if(vec.empty() || vec[vec.size()-1] != a[i])
vec.push_back(a[i]);
i++;
}
}
return vec;
}
int main() {
vector<int> v1 = {2, 4, 6, 8};
vector<int> v2 = {1, 3, 7, 10, 13};
vector<int> vec = merge(v1, v2);
for(int i = 0; i < vec.size(); ++i) {
cout << vec[i] << " ";
}
cout << endl;
return 0;
}