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

3 Mixsort Implement a function or method in the language of your choice which ta

ID: 3776266 • Letter: 3

Question

3 Mixsort

Implement a function or method in the language of your choice which takes in a vector or list

Of integers and also takes in another integer d which we will refer to as depth. The function will

Recursively call quicksort similar to problem 2 while decrementing depth until the depth has

Reached 0. At which point the algorithm will switch over to the heapsort you implemented in

problem 1 to finish the sorting of the vector. For this problem also comment in the code what

the value of d needs to with respect to the size of the vector n for the algorithm to have worst

case run time of O(n log(n)).

please code in c++.

Explanation / Answer

You can create a custom comparison function to use with std::sort. This function would have to check if the string begins with a numeric value. If it does, convert the numeric part of each string to an int using some mechanism like a stringstream. Then compare the two integer values. If the values compare equally, compare the non-numeric part of the strings lexicographically. Otherwise, if the strings don't contain a numeric part, simply compare the two strings lexicographically as normal.

Basically, something like the following (untested) comparison function:

And then...