Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

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_2

Step: 3

blur-text-image_step3

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