29.7k views
20 votes
You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order without using any other array space.Implementation instruction:1) Define one array of size 18 for A and the other array of size 5 for B.2) Initialize A by inputting 13 integers in the ascending order, and Initialize B by inputting 5 integers in the ascending order.

User JofoCodin
by
4.8k points

1 Answer

11 votes

Answer:

#include <iostream>

using namespace std;

int main(){

int arrayA[18] = {1,2,3,4,5,6,7,8,9,10,11,12,13};

int n = arrayA.length();

int arrayB[5] = {14,15,16,17,18};

for (int i = 0; i < arrayB.length(); i++){

arrayA[n] = array[i];

n++;

}

}

Step-by-step explanation:

The C++ program defines two arrays namely; "arrayA" and "arrayB". The first array has a space size of 18 while the second array has a size of 5. In the program, the second array is merged into the first array

User Julien Blanchard
by
5.0k points