"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

How a pointer differs from a reference?

972


What size is allocated to the union variable?

797


What is the use of 'using' declaration in c++?

859


Explain the different access specifiers for the class member in c++.

747


Explain the differences between list x; & list x();.

772


What is the best it certification?

825


Explain differences between new() and delete()?

828


What are the various oops concepts in c++?

799


What type of question are asked in GE code writing test based on c++ data structures and pointers?

3714


Why should we use null or zero in a program?

795


What is the use of object in c++?

818


Which is the best c++ compiler for beginners?

791


What will strcmp("Astring", "Astring"); return a) A positive value b) A negative value c) Zero

884


Is c++ platform dependent?

839


What are the differences between new and malloc?

826