qsort
Purpose
Sorts a table of data in place.
Library
Standard C Library (libc.a)
Syntax
void qsort ((char *) base, nel, sizeof (*base), compar)
unsigned int nel;
int (*compar) ( );
Description
The qsort subroutine sorts a table of data in place. It
uses the "quicker-sort" algorithm.
The base parameter points to the element at the base of
the table. The nel parameter is the number of elements
in the table. The compar parameter is the name of the
comparison function. (See "alphasort" for one such com-
parison function.)
The comparison function must compare its parameters and
return a value as follows:
o If the first parameter is less than the second param-
eter, compar must return a value less than 0.
o If the first parameter is equal to the second param-
eter, compar must return 0.
o If the first parameter is greater than the second
parameter, compar must return a value greater than 0.
The comparison function need not compare every byte, so
arbitrary data can be contained in the elements in addi-
tion to the values being compared.
Note: The order in the output of two items that compare
equal is unpredictable.
The pointer to the base of the table should be of type
pointer-to-element, and cast to type pointer-to-
character.
Related Information
In this book: "alphasort," "bsearch," "lsearch, lfind,"
and "string."
The sort command in AIX Operating System Commands Refer-
ence.