#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 comparison function cmp() with two pointers to array elements. 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 the other one | less than zero (negative) |
| equal to the other one | zero |
| greater than the other one | greater than zero (positive) |
The arguments to qsort() are listed in the following table:
| Argument Name | Meaning |
|---|---|
| array | A pointer to the beginning (i.e., 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 |