Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your Task: Your task is to complete the function merge ( ) which takes arr [ ] , l , m , r as its

Your Task:
Your task is to complete the function merge() which takes arr[], l, m, r as its input parameters and modifies arr[] in-place such that it is sorted from position l to position r, and function mergeSort() which uses merge() to sort the array in ascending order using merge sort algorithm. I am supposed to fill in the incomplete code where it says "Add your code below this line". The incomplete code is: #include
using namespace std;
// Function to print an array
void printArray(double arr[], int size)
{
cout "The sorted list is: ";
for (int i=0; i size; i++)
cout arr[i]"";
cout endl;
}
void merge(double arr[], int l, int m, int r)
{
//Add your code below this line.
//Add your code above this line.
}
void mergeSort(double arr[], int l, int r)
{
//Add your code below this line.
//Add your code above this line.
}
int main()
{
int n;
cout"How many numbers are you going to sort?"> n;
double arr[n+1];
cout"Please input your numbers separated with space:"> arr[i];
mergeSort(arr,0, n-1);
printArray(arr, n);
return 0;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Choose an appropriate organizational pattern for your speech

Answered: 1 week ago

Question

Writing a Strong Conclusion

Answered: 1 week ago