qsort

Quick sort

#include <stdlib.h>
void qsort (
        void *base,
        size_t n,
        size_t w,
        long (*fcmp)(const void *, const void *)
)

Arguments

base Pointer to array in memory to be sorted
n Number of elements
w Size of each element
fcmp Pointer to comparison function

Return Value

None.

Explanation

The array pointed to by base is sorted using a quicksort algorithm. n specifies the number of elements in the array and w is the size of each element. fcmp is the comparison function and must return a value representing the result of the comparison as in bcmp(). qsort() calls malloc() internally so there must be sufficient space on the heap to perform the sort.