Write the FUSION function that constructs a FUS array sorted in ascending order with the elements of two arrays A and B sorted in ascending order. For two arrays of dimensions N and M, the table FUS will have the dimension N + M.
Write a program that tests the FUSION function using two arrays read from the keyboard and sorted using any sorting algorithm.
Difficulty level
Video recording
This exercise is mostly suitable for students
void FUSION(int A[], int B[], int FUS[], int N, int M)
{
int IA, IB, IFUS;
IA = 0, IB = 0; IFUS = 0;
while ((IA<N) && (IB<M))
if (A[IA]<B[IB])
{
FUS[IFUS] = A[IA];
IFUS++;
IA++;
}
else
{
FUS[IFUS] = B[IB];
IFUS++;
IB++;
}
while (IA<N)
{
FUS[IFUS] = A[IA];
IFUS++;
IA++;
}
while (IB<M)
{
FUS[IFUS] = B[IB];
IFUS++;
IB++;
}
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Same elements in binary search trees