Question: I have this bubble sort. I need to add a counter to check the comparisons. In order words, how often I check one element in
I have this bubble sort. I need to add a counter to check the comparisons. In order words, how often I check one element in the array against another. Am I doing it, right? If not, How can I fix it? Thank you
#include
void bubbleSort(int theArray[], int n) { int comparisons = 0; //counter is bool sorted = false; int pass = 1; while(!sorted && (pass
pass++; }//end while
cout << "Number of comparison: " << comparions; }//end bubbleSort;
void displayArray(int theArray[], int size) { for(int i=0; i int main() { int data[] = {1}; //int data1[] = {2, 1}; //int data2[] ={ 1,2}; int data3[] = {4, 1, 3, 2, 0, 7}; cout<<"The array data contains: " << endl; displayArray(data,1); cout< cout<<"The array data3 contains: " << endl; displayArray(data3,6); cout< int array8a[] = {1, 4, 23, 37, 2, 7,3, 9}; int array8b[] = {9,7,2, 37, 23, 4, 1, 3}; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
