"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 / foreverkushal

void MergeArray(int *A1, int A1Count, int *A2, int A2Count,
int *A3, int A3Count)
{
int i = 0, j = 0, k = 0;
while(i != A1Count && j != A2Count)
{
if (A1[i] < A2[j]) A3[k++] = A1[i++];
else A3[k++] = A2[j++];
}
if (i != A1Count)
{
while (i < A1Count) A3[k++] = A1[i++];
}
if (j != A2Count)
{
while (i < A2Count) A3[k++] = A2[j++];
}
}

Is This Answer Correct ?    23 Yes 43 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does new do in c++?

637


write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;

1460


What are friend functions in C++?

624


What is long in c++?

737


How can I disable the "echo" feature?

611






How a new operator differs from the operator new?

625


What is the difference between containment and delegation?

704


Write a program to show polymorphism in C++?

630


Name the debugging methods that are used to solve problems?

581


What is a manipulative person?

541


Is c++ pass by reference or value?

570


Write a struct time where integer m, h, s are its members?

519


What operators can you overload in c++?

596


What are c++ variables?

539


Is it possible to provide default values while overloading a binary operator?

766