Question: Write a function insertInOrder() which inserts each of the elements in the source array to the destination We are currently working on Arrays and Algorithms

Write a function insertInOrder() which inserts each of the elements in the source array to the destination

We are currently working on Arrays and Algorithms and I would appreciate some help with the function and below the picture is the support file.

Write a function insertInOrder() which inserts each of the elements in the

/**

CS 150 PARTIALLY FILLED ARRAYS

Follow the instructions on your handout to complete the

requested function. You may not use any library functions

or include any headers, except for for size_t.

*/

#include // size_t for sizes and indexes

///////////////// WRITE YOUR FUNCTION BELOW THIS LINE ///////////////////////

// function here

///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE ///////////////////////

// These are OK after the function

#include

#include

#include

using namespace std;

string toString(const int a[], size_t size);

void studentTests()

{

cout

cout

cout

const int CAP = 5; // all arrays are size 5

{

int src[CAP] = {5, 7, 9};

int dest[CAP] = {6, 8};

size_t dSize = 2;

cout

cout "

cout "

bool ok = insertInOrder(dest, dSize, CAP, src, 3);

cout " "

cout [5, 6, 7, 8, 9], return->true"

}

{

int src[CAP] = {9, 5, 7};

int dest[CAP] = {6, 8};

size_t dSize = 2;

cout

cout "

cout "

bool ok = insertInOrder(dest, dSize, CAP, src, 3);

cout " "

cout [5, 6, 7, 8, 9], return->true"

}

{

int src[CAP] = {5, 7, 9, 2};

int dest[CAP] = {6, 8};

size_t dSize = 2;

cout

cout "

cout "

bool ok = insertInOrder(dest, dSize, CAP, src, 4);

cout " "

cout [6, 8], return->false"

}

cout

cout

}

string toString(const int a[], size_t size)

{

ostringstream out;

out

if (size > 0)

{

out

for (size_t i = 1; i

out

}

out

return out.str();

}

int main()

{

studentTests();

}

5 THE insertInOrder PROBLEM Write the function insertInorder() which inserts each of the elements in the source array into the ordered position in the destination array. You may assume that the destination array is already in sorted order. Here is a short example: int src[50]- 5, 7, 9); int dest[50] {6, 8); size t dSize - 2; bool okinsertInOrder(dest, dSize, 50, src, 3); As you can see the function takes 5 arguments: The destination array and its size, which may both be modified. The destination capacity, the source array and the source size, which are not modified. . . In the example shown above, the function will return true (since it can succeed) and the resulting array will contain: 5, 6, 7, 8, 9. The new dSize will be 5. The function returns false if it fails. The only reason it could fail is if inserting the new elements would cause the capacity to be exceeded, in which case the destination array should not be changed in any way

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!