Question: I want to write a C++ code that compares the number of comparisons done by these four different sorting algorithms: 1) The standard C++ STL

I want to write a C++ code that compares the number of comparisons done by these four different sorting algorithms:

1) The standard C++ STL sort function (not the C qsort function!). Of course, this sort is already pre-made, so you dont need to implement it. But you do need to find a way to count the number of comparisons it does.

2) Selection sort, implemented as a priority queue based on an unordered vector.

3) Insertion sort, implemented as a priority queue based on a sorted vector.

4) Heapsort, implemented as a priority queue based on a heap.

this is what each sort has to do :

Write code that counts the number of comparisons done by the 4 different sorts for n = 5000, 10000, 15000, ..., 100000. When this is done, we should have exactly 4*20 = 80 different numbers, one for each sort and value of n.

// Pre-condition: // none // Post-condition: // v is re-arranged into ascending sorted order void sort(vector& v) { // // Step 1: read v into an empty priority queue // // // Step 2: read all the elements from priority queues, // from smallest to biggest, back into v } 

The challenge is that I can't use a traditional implementation (which is not based on a priority queue). I need to use a priority queue implementation.

This has to be done only using simple C++ functions. like I can only use new and delete to allocate and de-allocate memory. NOT malloc and free, NOT C++ smart pointer, NOT any pre-defined data structures (such as arrays or vectors) or algorithms.

A bing Thank you in advance to all you experts!

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!