#include #include typedef int Item; #define key(A) (A) #define lt(A, B) (key(A) < key(B)) // less than #define le(A, B) (key(A) <= key(B)) // less than or equal to #define ge(A, B) (key(A) >= key(B)) // greater than or equal to #define gt(A, B) (key(A) > key(B)) // greater than void swap(Item a[], int i, int j) { Item temp = a[i]; a[i] = a[j]; a[j] = temp; } void bubbleSort(Item items[], int lo, int hi) { for (int i = hi; i > lo; i--) { bool swapped = false; for (int j = lo; j < i; j++) { if (gt(items[j], items[j + 1])) { swap(items, j, j + 1); swapped = true; } } if (!swapped) { break; } } } int main(void) { Item a[] = {42, 7, 19, 3, 88, 1}; int n = sizeof(a) / sizeof(a[0]); bubbleSort(a, 0, n - 1); for (int i = 0; i < n; i++) { printf("%d ", a[i]); } printf("\n"); return 0; }