"How will you merge these two arrays? Write the program
Array: A 1 18 22 43
Array: B 3 4 6 20 34 46 55
Output Array: C 1 3 4 6 18 20 22 34 43 46 55"

Answer Posted / sampath

hi friends !
i use java code it simple idea

class Sort
{
public static void main()
{
int A[]={1,18,22,43};
int B[]={3,4,6,20,34,46,55}

int lenA=A.length;
int lenB=B.length;

int n=lenA+lenB; //find the array size


int C[]=new int[n];
int i,j,temp;

for(i=0;i<n;i++) //copy the two array into C array
{
if(i<lenA)
C[i]=A[i];
else
C[i]=B[i-lenA];
}


for(i=0;i<n;i++) //place each element in to correct position
{
for(j=0;j<n;j++)
{
if(c[i]>c[j]) //swapping
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
for(i=0;i<n;i++)// display output
{
System.Out.Print(c[i]+",");
}
}

Is This Answer Correct ?    5 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are single and multiple inheritances in c++?

776


What is difference between c++ and c ++ 14?

777


When do you call copy constructors?

871


Define a nested class. Explain how it can be useful.

845


What does new do in c++?

820


Describe the syntax of single inheritance in C++?

844


Can member functions be private?

783


Explain "const" reference arguments in function?

810


What is auto type c++?

856


how to connect with oracle 9i with server in socket program in c/c++

2081


Explain stack unwinding.

839


What are inline functions? What is the syntax for defining an inline function?

813


Is map thread safe c++?

856


Can you overload the operator+ for short integers?

797


What is a far pointer? where we use it?

807