"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

Is c++ the hardest programming language?

655


Can java be faster than c++?

680


Can we use clrscr in c++?

548


Can notepad ++ run c++?

558


What is function declaration in c++ with example?

554






Is vector a class in c++?

612


What are the 3 levels of programming languages?

548


Will a recursive function without an end condition every quit, in practice a) Compiler-Specific (Some can convert to an infinite loop) b) No c) Yes

600


Why pointer is used in c++?

629


What is a sequence in c++?

598


Is c better than c++?

643


What is a linked list in c++?

559


What is an associative container in c++?

562


what are the events occur in intr activated on interrupt vector table

1190


Why we use #include conio h in c++?

606