"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

Name the implicit member functions of a class.

596


Is c++ the most powerful language?

566


Describe public access specifiers?

581


What is the output of the following program? Why?

624


What is the prototype of printf function?

653






the first character in the variable name must be an a) special symbol b) number c) alphabet

605


Can a program run without main in c++?

586


Why pointer is used in c++?

615


How is c++ used in the real world?

573


Do you need a main function in c++?

561


What are the benefits of c++?

569


Define Virtual function in C++.

625


What is the difference between function overloading and operator overloading?

574


What is ios flag in c++?

682


How to give an alternate name to a namespace?

591