Content deleted Content added
Reverted 1 edit by Ivoncheung (talk): WP:OR; and, this article is about the standard C function qsort, not about implementing quicksort in C. (TW) |
|||
Line 15:
/* Comparison function. Receives two generic (void) pointers. */
int compare(const void *p, const void *q) {
int x = *(const int *)p;
int y = *(const int *)q;
Line 23 ⟶ 21:
/* Avoid return x - y, which can cause undefined behaviour
because of signed integer overflow. */
if (x
else
return
}
/* Sort an array of n integers, pointed to by a. */
void sort_ints(int *a, size_t n) {
qsort(a, n, sizeof(int), compare);
}
|