"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
Can you declare an array without a size in c++?
Can we specify variable field width in a scanf() format string? If possible how?
Is it possible to provide special behavior for one instance of a template but not for other instances?
Which is best c++ or java?
What is code reusability in c++?
What is a volatile variable in c++?
What is the use of lambda in c++?
What is the best free c++ compiler for windows?
What is nested class in c++?
Can the creation of operator** is allowed to perform the to-the-power-of operations?
write asingle linked list which read from two list & the do the following 1 sort the prime & nonprime num (prime should be less tn nonprime) 2 each node has a prime num followd by nonprime 3 add a new node into its sutable plce 4 erase the most three duplicated non prime num 5 find the least duplicated prime num
Write about the use of the virtual destructor?
How to defines the function in c++?
Explain data encapsulation?
Does a derived class inherit or doesn't inherit?