Please Provide Code in Either JAVA or C and provide CLEAR Ex
Please Provide Code in Either JAVA or C++ and provide CLEAR! Explanatin on what you are doing in the code. For goodfeedbackand full points. 8
Problem The merging procedure is an essential part of \"Merge Sort\" (which is considered in one of the next problems) Given: A positive integer n 105 and a sorted array A1.nl of integers from -10 to 105, a positive integer m 105 and a sorted array B1..m of integers from -105 to 105 Return: A sorted array Cl1..n+ ml containing all the elements of A and B Sample Dataset 2 4 10 18 5 11 12 Sample output -5 2 4 10 11 12 18 Hint click to collapse The very first element of C is either A1 or B1 whichever is smaller The rest of C can then be constructed recursively.Solution
#include <iostream>
using namespace std;
int main()
{
int n,m;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cin>>m;
int b[m];
for(int i=0;i<m;i++)
{
cin>>b[i];
}
int c[n+m];
int p=0,q=0,r=0;
while(p<n&&q<m)
{
if(a[p]<b[q])
{
c[r] = a[p];
p++;
}
else
{
c[r] = b[q];
q++;
}
r++;
}
while(p<n)
{
c[r] = a[p];
p++;
r++;
}
while(q<m)
{
c[r] = b[q];
q++;
r++;
}
for(int i=0;i<n+m;i++)
{
cout<<c[i]<<\' \';
}
cout<<endl;
return 0;
}

