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

Write C++ program to compare the performance of three sorting algorithms: Select

ID: 3662027 • Letter: W

Question

Write C++ program to compare the performance of three sorting algorithms: Selection, Insertion and QuickSort. Use the qsort() function available in <cstdlib>. You will need to implement the comparison function to be used by qsort().

The main function should implement like this:

Build three arrays using random number generation (the three arrays need to be identical), limit the numbers to 2-3 digits

Print one of the arrays on the screen so you can see what you generated

Call selectionSort(), which should count and return the number of comparisons performed

Call insertionSort(), which should count and return the number of comparisons performed

Call qsort(), keep a counter in the compar() function. It is ok to use a global variable for this one

Print the sorted array and the number of comparisons performed by each one of the sorting algorithms

Call each one of the algorithms again on the sorted arrays

Print the number of comparisons performed by each one

Build new arrays with numbers sorted in inverse order

Call each algorithm on the inverse-sorted arrays

Print the number of comparisons performed by each one.

To generate random numbers, make sure to:

Reset the seed by calling srand(time(0)); #include <ctime>

Call rand() to generate the numbers

Use the modulus operator % to bring the numbers to 2-3 digits only

Explanation / Answer

Below is the link to get the code file. I was not able to maintain proper indentation here.

Sort.cpp

https://drive.google.com/file/d/0B9P4w87kevGhUGpNWGNkNUxNTEE/view?usp=sharing

Random.cpp

https://drive.google.com/file/d/0B9P4w87kevGhRGVxZFhob3JJdkU/view?usp=sharing

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote