Merge Two Sorted Vectors
hardQuestion 572Write a function vector<int> mergeSorted(const vector<int>& a, const vector<int>& b) where a and b are each sorted ascending. Return a new vector containing every element of both, sorted ascending. Requirements:
1. Keep one iterator into a and one into b.
2. While both have elements left, compare the two current elements, push the smaller one into the result and advance only that iterator. When they are equal, take the one from a first.
3. When one input runs out, append everything remaining in the other (its leftover range).
4. Do not call sort or std::merge; either input may be empty.
The test prints the result's elements separated by spaces on one line. For {1, 3, 5} and {2, 4, 6} the line is 1 2 3 4 5 6; for {1, 4, 9} and {2, 3} it is 1 2 3 4 9.
Do NOT write a main function.
Expected output
1 2 3 4 5 6 1 2 3 4 9
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...