(ANSI Standard)
#include <stdlib.h> qsort( s, N, size, compare );
"qsort" sorts the elements of an array using the comparison function indicated by "compar".
For example, when sorting strings, the following function is a good choice for "compar".
scmp( void *sp1, void *sp2 ) { return( strcmp(*(char **)sp1, *(char **)sp2) ); }
The casting operation is necessary because of the requirements of "strcmp".
This function is called "qsort" because its original implementation used a "quicksort" algorithm. For reasons of efficiency, the algorithm has since been changed to a shell-sort; however, the name has been retained for compatibility with older programs. Since the way of calling "qsort" will not change, the actual sorting algorithm used will not be relevant for most users.
Copyright © 1996, Thinkage Ltd.