Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sort(1)

bsearch(3C)

lsearch(3C)

string(3C)

QSORT(3C)  —  Silicon Graphics

NAME

qsort − quicker sort

SYNOPSIS

void qsort ((char ∗) base, nel, width, compar)
unsigned int 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; sizeof (base) should be used.  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 according as the first argument is to be considered less than, equal to, or greater than the second. 

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.

EXAMPLE

structentry {
char∗name;
intflags;
};

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. 

SEE ALSO

sort(1), bsearch(3C), lsearch(3C), string(3C). 

Version 2.3  —  July 04, 1985

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026