"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 does it mean to declare a member function as virtual?
If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?
How do you traverse a btree in backward in-order?
Must accepts "Maestro Cards" Tax for bike should be less than 15 Total number of lanes is more than 10 Must provides monthly pass Write a method: boolean isGoodTollBridge(String[] cardsAccepted, String[] tollTax, boolean hasMonthlyPass, int numberOfLanes); String[] cardsAccepted A String array of names of card types accepted for payment of toll tax, it can be null if the toll does not accept any card String[] tollTax A String array of toll tax chart (say “Train : 300â€Â,â€ÂBullCart : 10â€Â) boolean hasMonthlyPass This parameter defines whether there is any monthly pass available or not int numberOfLanes This parameter defines the number of lanes for each side
What kind of jobs can I get with c++?
write a program that withdrawals,deposits,balance check,shows mini statement. (using functions,pointers and arrays)
What is the use of c++ programming language in real life?
How to implement is-a and has-a class relationships?
What is the difference between a template and a macro?
What is the difference between a "copy constructor" and an "assignment operator" in C++?
What is c++ programming language?
What is a set in c++?
Is map sorted c++?
What are pointer-to-members in C++? Give their syntax.
True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends