1.write a program to merge the arrays
2.write efficient code for extracting unique elements from a
sorted list of array?

Answer Posted / nishant chauhan

//#include<stdio.h>
#include<conio.h>
#include<iostream>
using namespace std;

int merge(int A[],int B[],int C[],int m,int n)
{
int i=0, j=0, k=0,len=0;
while (i < m && j < n)
{
if (A[i] <B[j])
{
C[k] = A[i];
i++;
len++;
}
else if(A[i] >B[j])
{
C[k] = B[j];
j++;
len++;
}
else
{
C[k]=A[i];
i++;j++;
len++;
}
k++;
}

if (i < m)
{
for (int p = i; p < m; p++)
{
C[k] = A[p];
k++;len++;
}

}
else
{
for (int p = j; p < n; p++)
{
C[k] = B[p];
k++; len++;
}
}
return len;
}

main ()
{
int a[20],b[20],c[30],m,n;
cout<<"enter the length of first array: ";
cin>>m;
cout<<"enter the array: ";
for(int i=0;i<m;i++)
cin>>a[i];
cout<<"enter the length of second array: ";
cin>>n;
cout<<"enter the array: ";
for(int j=0;j<n;j++)
cin>>b[j];
int length=merge(a,b,c,m,n);
cout<<"resulting merging array is: ";
for(int k=0;k<length;k++)
cout<<c[k]<<" ";
getch();
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are inbuilt functions in c?

560


the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b

1906


Sir i need notes for structure,functions,pointers in c language can you help me please

1943


What are local static variables?

619


What are the characteristics of arrays in c?

614






What is dynamic dispatch in c++?

556


What are the types of assignment statements?

630


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

613


What is hashing in c?

642


Explain how can you check to see whether a symbol is defined?

661


plz let me know how to become a telecom protocol tester. thank you.

1742


What is sorting in c plus plus?

565


What oops means?

582


Why flag is used in c?

651


What is the Purpose of 'extern' keyword in a function declaration?

654