"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
What is a stack? How it can be implemented?
What is static class data?
What is the use of main function in c++?
What is the difference between *p++ and (*p)++ ?
What is null and void pointer?
Is it possible to use a new for the reallocation of pointers ?
what is multi-threading in C++?
Arrange Doubly linked list in the ascending order of its integral value and replace integer 5 with 7?
which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?
What is an accessor in c++?
What is the difference between equal to (==) and assignment operator (=)?
What is c++ hiding?
Why is polymorphism useful?
What apps are written in c++?
What is the c++ programming language used for?