Use C language to write a set of random number bubble sorting, selection sorting, insertion sorting, quick sorting, merge sorting, output the number of comparisons and the number of exchanges...

Bubble sort: int n, a[maxsize], i, j, temp; for (i = 0; i < n - 1; i++) { for (j = 0; j < n - i - 1; j++) { if (a[j] > a[j + 1]) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } } } // output comparison Number of times and number of exchanges: printf("Number of comparisons: %d \n", n * (n - 1) / 2); printf(

Guess you like

Origin blog.csdn.net/weixin_35754962/article/details/129577001