qsort(3C) qsort(3C)NAME qsort - performs a quicker sort SYNOPSIS void qsort(base, nel, width, compar) char *base; unsigned nel, width; int(*compar)(); DESCRIPTION qsort is an implementation of the quicker-sort algorithm. It sorts a table of data in place. base points to the element at the base of the table. nel is the number of elements in the table. width is the width of an element in bytes. compar is the name of the comparison function, which is called with two arguments that point to the elements being compared. The function must return an integer less than, equal to, or greater than zero if the first argument is to be considered less than, equal to, or greater than the second. EXAMPLES struct entry { char *name; int flags; }; main() { struct entry hp[100]; int entcmp(); int i, count; for (i = 0; i < (count = 100); i++) { /* fill the structure with the name and flags */ ... } qsort( (char *) hp, count, sizeof (hp[0]), entcmp); } entcmp(ep,ep2) struct entry *ep, *ep2; { return (strcmp(ep->name, ep2->name)); } will sort a set of names with associated flags in ASCII order. January 1992 1
qsort(3C) qsort(3C)NOTES The pointer to the base of the table should be of type pointer-to-element, and cast to type pointer-to-character. The comparison function need not compare every byte, so arbitrary data may be contained in the elements in addition to the values being compared. The order in the output of the two items that compare as equal is unpredictable. SEE ALSO bsearch(3C), lsearch(3C), string(3C) sort(1) in A/UX Command Reference 2 January 1992