1. Write a function that will merge the contents of two sorted(ascending order)
ID: 3617749 • Letter: 1
Question
1. Write a function that will merge the contents of two sorted(ascending order) arrays of type double values, storing the resultin an array output parameter (still in ascending order). Thefunction should not assume that both its input parameter arrays arethe same length but can assume that one array does not contain twocopies of the same value. The result array should also contain noduplicate values. As an example, the two arrays and the resultingmerged array may look like the following:
First array:
-10.5
-1.8
3.5
6.3
7.2
Second array:
-1.8
3.1
6.3
empty
empty
Merged array:
-10.5
-1.8
3.1
3.5
6.3
7.2
Note: when one of the input arrays has been exhausted, do notforget to copy the remaining data in the other array into theresult array. Test your function with cases in which (1) the firstarray is exhausted first, and (2) the second array is exhaustedfirst .and (3) the two arrays are exhausted at the same time(i.e., they end with the same value). Remember that the arraysinput to this function must already besorted.
-10.5
-1.8
3.5
6.3
7.2
Explanation / Answer
please rate - thanks #include #include int merge(double[], int , double[], int , double[] ); int fill(double[], int, double[],int,int); void print(double[],int,char[]); int main() {doubleL[]={-10.5,-1.8,3.5,6.3,7.2},M[]={-1.8,3.1,6.3},res[50]; int lsize=5,msize=3,rsize=0; rsize=merge(L,lsize,M, msize,res); print(L,lsize,"Original Array 1"); print(M,msize,"Original Array 2"); print(res,rsize,"Merged Array"); getch(); return 0; } void print(double A[], int len,char mess[]) {int i; printf("%s ",mess); for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.