Question: I have this program, how can I put a counter to count the number of comparisons and how can I put a cout statement to

I have this program, how can I put a counter to count the number of comparisons and how can I put a cout statement to print out the number of comparisons?

//This is a C++ Program to Sort an Array using Bucket Sort #include using namespace std; //Bucket Sort void bucketSort (int array[], int n) { //Here range is [1,100] int m = 101; //Create m empty buckets int buckets[m]; //Intialize all buckets to 0 for (int i = 0; i < m; ++i) buckets[i] = 0; //Increment the number of times each element is present in the input //array. Insert them in the buckets for (int i = 0; i < n; ++i) ++buckets[array[i]]; //Sort using insertion sort and concatenate for (int i = 0, j = 0; j < m; ++j) for (int k = buckets[j]; k > 0; --k) array[i++] = j; } //Driver function to test above function int main() { int inputArray[] = {1, 4, 0, 4, 0, 0, 3, 4, 0, 3}; int n = sizeof (inputArray) / sizeof (inputArray[0]); bucketSort(inputArray, n); cout << "Sorted Array : " << endl; for (int i = 0; i < n; ++i) cout << inputArray[i] << " "; cout<< endl; return 0; }

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!