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
What is wild pointer in c with example?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
Explain the binary height balanced tree?
Is array a primitive data type in c?
What the different types of arrays in c?
An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?
how do you execute a c program in unix.
printf(), scanf() these are a) library functions b) userdefined functions c) system functions d) they are not functions
What are register variables? What are the advantage of using register variables?
What is a macro, and explain how do you use it?
hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel
What does 3 periods mean in texting?
Describe newline escape sequence with a sample program?
What is a string?
What is malloc and calloc?