"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
Is c the same as c++?
Write a c program for binary addition of two 8 bit numbers.
Explain what are accessor methods?
We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?
What is polymorphism in c++? Explain with an example?
Explain the difference between c & c++?
Why c++ is faster than java?
What is a storage class? Mention the storage classes in c++.
What is the object serialization?
Is empty stack c++?
Why is c++ a mid-level programming language?
What is oop in c++?
Explain the benefits of proper inheritance.
why and when we can declar member fuction as a private in the class?
Why isn't sizeof for a struct equal to the sum of sizeof of each member?