Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a program that reads two arrays from a user and sorts each array. After

ID: 3620027 • Letter: D

Question

Develop a program that reads two arrays from a user and sorts each array. After that merge the two sorted arrays into an array. Note that the merged array should also keep the sorted order properly. In this program, you should use dynamic
arrays.

The following shows a sample run of your program:
Enter the size of first array: 5
Enter array content: 33 11 55 66 44
Sorted result: 11 33 44 55 66
Enter the size of second array: 4
Enter array content: 22 88 54 77
Sorted result: 22 54 77 88
Combined sorted array: 11 22 33 44 54 55 66 77 88

I have created a program, but I cannot seem to get the sorting correct. Can someone help me modify my code with that using dynamic arrays? Please Help. Here is my code:

#include

using namespace std;

int main()
{
int input, size, size2;
int * Ptr1;
int * Ptr2;
int * Ptr3;

cout<<"Enter the size of the first array: ";
cin>>input;
size = input;
Ptr1 = new int [input];


cout<<"Enter the array content: ";
for (int i=0; i
{
cin >> Ptr1[i];
}

cout<<"Enter the size of the second array: ";
cin>>input;
size2 = input;

Ptr2 = new int [input];

cout<<"Enter the array content: ";
for (int i=0; i
{
cin >> Ptr2[i];
}

Ptr3 = new int[size + size2];
for (int i=0; i
{
Ptr3[i]=Ptr1[i];

}

for (int i=size; i<(size+size2); i++)
{
Ptr3[i]=Ptr2[i-size];
}

cout<<"The combined array is: ";

for(int i = 0; i < (size+size2); i++)
{
cout << Ptr3[i] << " ";

}

cout << endl;

delete [] Ptr1;
delete [] Ptr2;
delete [] Ptr3;

return 0;
};>;>;>

Explanation / Answer

The program you have written does not have any code for sorting. Use any sorting such as insertion sort ,bubble sort or merge sort to sort the two arrays. This is a function for insertion sort. Pass the array and size of the array. (Array should have elements starting for index 1 and not 0) void sort(int a[],int n) { int i,j,key; for(i=2;i0&&key