Question: Could anyone complete normal vector sort in C++? I need to keep track of how much work they do while they do their sorting as

Could anyone complete normal vector sort in C++?

I need to keep track of how much work they do while they do their sorting as well. I need to count the number of comparisons it does and how many moves or swaps the algorithm does.

sample bubble sort:

void instrumentedBubbleSort( vector & a, SortStats & stats ) { bool swapp = true; while(swapp){ swapp = false; for (size_t i = 0; i < a.size()-1; i++) { if ( stats.compares++ && a[i] > a[i+1] ) { // Log the comparison stats.moves++; // Log that we swapped (moved) a[i] += a[i+1]; a[i+1] = a[i] - a[i+1]; a[i] -= a[i+1]; swapp = true; } } } }

need insertion, merge, and quicksort.

void instrumentedInsertionSort( vector & a, SortStats & stats ) {

}

void instrumentedMergeSort( vector & a, SortStats & stats ) { }

void instrumentedQuickSort( vector & a, SortStats & stats ) { }

need to track compares + moves for all sorts and please attack short comment to understand how it works.

thx

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!