“C Language” – Counting ‘comparisons‘ (NOTSWAPS) in a BubbleSort Algorithm Array.
Advice on the code required to a) countcomparisons and b) output result – by editing thefollowing code please?
________________
#include <stdio.h>
#define SIZE 10
void bubbleSort(int * const array, const size_t size);
int main(void)
{
// initialize array a
int a[SIZE] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
puts(“Data items in original order”);
// loop through array a
for (size_t i = 0; i < SIZE; ++i) {
printf(“%4d”, a[i]);
}
bubbleSort(a, SIZE); // sort the array
puts(“nData items in ascending order”);
// loop through array a
for (size_t i = 0; i < SIZE; ++i) {
printf(“%4d”, a[i]);
}
puts(“”);
}
// sort an array
PayPal Gateway not configured
PayPal Gateway not configured