Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

( we must use struct in array ) Suppose A, B, C are arrays of integers of size M

ID: 3590985 • Letter: #

Question

(we must use struct in array) Suppose A, B, C are arrays of integers of size M, N, and M + N respectively. The numbers in array A appear in ascending order while the numbers in array B appear in descending order. Write a user defined function in C++ to produce third array C by merging arrays A and B in ascending order. Use A, B and C as arguments in the function. You will need to ask user to input M and N, and based on those inputs user needs to fill the arrays A and B in an appropriate order. If user wants to input wrong order of values, your program should not accept it, and should ask for appropriate value.

Explanation / Answer

#include<iostream.h>
using namespace std;
void Mrge (int A[120], int B[120], int C[250], int N, int M, int &);
int main()
{
m A[120] , B[120] , C[250] ,l,n,m,k;
cout<<" Enter no of Components t to insert in first array";
cin>>n;
WVW
cout<<"Enter Components in increasing order ";
for (i=0; l<n;l++)
{
cout<<"Enter element "<<l+1<<" : ;
cin>>A[l] ;
}
cout<<" Enter no of Components to lnsert in second
array ";
cin>>m;
cout<<"Enter Components in decreasing order ";
for (l=0; l<m; l++)
{
cout<<"Enter Components "<<l+1<<": ";
Cin>>B[l];
Mrge)A,B,C,n,m,k) ;
cout<<" The Merged Array in increasing Order"<<endl;
for(l=0; l<k;l++)
{
cout<<C [1] <<" " ;
}
cin. ignore ( ) ;
cin. get g ) ;
return 0;
}
void Mrge (int A[], int B[], int C[], int N, int M, int &K)
{
int L=0, J=M—1;
K=0;
while (L<N && J>=0)
{
if (A[L]<B[J])
C[K++]=A[L++];
else if (A[L]>B[J])
C[K++]=B[J—-];
else
{
QLK++]=A[L++];
J—-;
}
for (int T=L;T<N; T++)
C[K++]=A[T];
for (int T=J;T>=0;T—-)
C[K++]=B[T];
}