#include <stdlib.h>
void *qsort(const void *array, size_t n,
size_t size, cmp_func cmp);
qsort() sorts the array according to the ordering implemented by the comparison function. It calls the cmp() comparison function with two pointers to array elements ( *key, *other). Thus, the type cmp_func() can be declared as:
typedef int (*cmp_func)(const void *key,
const void *other);
The comparison function returns an integer according to the following table.
| *key Element Value | Return Value |
|---|---|
| Less than *other | Less than zero (negative) |
| Equal to *other | Zero |
| Greater than *other | Greater than zero (positive) |
The arguments to qsort() are listed in the following table.
| Argument Name | Meaning |
|---|---|
| array | A pointer to the beginning (the first element) of the array to be sorted |
| n | The number of elements in the array |
| size | The size (in bytes) of one element in the table |
| cmp() | The comparison function |