Write a function to merge two sorted arrays. (in the comments below, @pre refers
ID: 3611416 • Letter: W
Question
Write a function to merge two sorted arrays.(in the comments below, @pre refers to a condition true to thefunction call, whereas @post refers to a condition true immediatelyfollowing the function call):
typedef int Item;
void merge(const Item L[], const int lsize, const Item M[], constint msize, Item res[], int& rsize);
//@pre arrays L and M are considered sorted (innon-decreasing order with possible duplicates).
//@pre: lsize is set the number of vaild elements in L.
//@pre: msize is set to the number of vaild elements in M.
//@pre: res is as least as large as L and M combined.
//@post: the array res contains copies of every item in L andM in sorted order.
//@post: rsize is set to the number of vaild elements in res.
//It is required that the resulting array, res, be generated duringa single linear pass through the arrays L
// and M.
Example:
Argument Value
L 8 8 12 34 56 56 56 89
lsize 8
M 2 4 56 56 62 70
msize 6
res 2 4 8 8 12 34 56 56 56 56 56 62 70 89
rsize 14