Syntax | #include <stdlib.h> void qsort (void * base, size_t nel, size_t width, int ( *compar) (const void *, const void *)); |
Description
The qsort()
function is an implementation of the quicksort algorithm. It sorts a table of data
in place. The contents of the table are sorted in ascending order according to the The comparison function may be defined as follows: /* Program fragment 1 compares two char values */ int comp(const void *a, const void *b) { if(*((const char *)a) < *((const char *) b) ) return(-1); else if(*((const char *)a) > *((const char *) b ) ) return(1); return(0); } /* Program fragment 2 compares two integer values */ int compare(const void *a, const void *b) { return ( *((const int *) a) - *((const int *) b) ); } | |
Notes | The comparison function need not compare every byte, so arbitrary data may be contained Extension |
See also |
|