"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
What is ctime c++?
What is the full name of logo?
Are vectors faster than arrays?
Is java based off c++?
Can we use clrscr in c++?
What is near, far and huge pointers? How many bytes are occupied by them?
What it is and how it might be called (2 methods).
What c++ library is string in?
What are the stages in the development cycle?
What is this weird colon-member (" : ") syntax in the constructor?
Why c++ is faster than java?
What is #include cmath?
Do you know what are static and dynamic type checking?
If a function doesn’t return a value, how do you declare the function?
In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h