1 | #include <limits.h> |
---|---|
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | |
5 | int compare_ints(const void *a, const void *b) { |
6 | int arg1 = *(const int *)a; |
7 | int arg2 = *(const int *)b; |
8 | |
9 | if (arg1 < arg2) // breakpoint 1 |
10 | return -1; |
11 | if (arg1 > arg2) |
12 | return 1; |
13 | return 0; |
14 | } |
15 | |
16 | int main(void) { |
17 | int ints[] = {-2, 99, 0, -743, 2, INT_MIN, 4}; |
18 | int size = sizeof ints / sizeof *ints; |
19 | |
20 | qsort(base: ints, nmemb: size, size: sizeof(int), compar: compare_ints); |
21 | |
22 | for (int i = 0; i < size; i++) { |
23 | printf(format: "%d ", ints[i]); |
24 | } |
25 | |
26 | printf(format: "\n"); |
27 | return 0; |
28 | } |
29 |