#include <stdio.h>
void bsort(char *arr, int len) { int i, j, k, t, cnt = 0;;
for(i = len - 1; i > 0; i = k) {
for (j = 0, k = 0; j < i; j++) {
if (*(arr + j) > *(arr + j + 1)) { t = *(arr + j); *(arr + j) = *(arr + j + 1); *(arr + j + 1) = t;
k = j; } } cnt++; }
printf("cycle %d\n", cnt); }
int main(int argc, char *argv[]) { int i = 0; char arr[10] = {3, 2, 5, 4, 4, 5, 6, 7, 8, 9};
while (i < 10) { printf("%d ", arr[i++]); } i = 0; putchar('\n');
bsort(arr, 10); while (i < 10) { printf("%d ", arr[i++]); } putchar('\n'); }
|