Question: Problem 4(b) (Implement k-way templated Merge Sort, 25%) Write your own templated implementation of the Merge Sort algorithm that works with any class T, and

 Problem 4(b) (Implement k-way templated Merge Sort, 25%) Write your own

Problem 4(b) (Implement k-way templated Merge Sort, 25%) Write your own templated implementation of the Merge Sort algorithm that works with any class T, and any Comparator functor for T. Put your implementation in file msort.h: don't make a msort.cpp file (because you're using templates). Your mergeSort() function must take a vector, an integer k, and a comparator object i.e., functor) that has an operator() defined for it. In other words, it must have the following signature. template void mergeSort (std::vector& myArray, int k, Comparator comp); Passing in different Comparator objects allows you to change the sorting criterion. The integer k is used as follows: in normal Merge Sort, you divide the array into two equal parts, sort each of them, and then call the merge function we saw in class. In k-way Merge Sort, you divide the array into k equal parts, sort each part, and then run a k-way merge function that you will need to write. Whereas 2-way merge needs two indices to traverse the two halves of the array, k-way merge will need k indices, so an array of indices may be a good idea

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!