Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sort(1)

QSORT(3)  —  UNIX Programmer’s Manual

NAME

qsort − quicker sort

SYNOPSIS

qsort(base, nel, width, compar)
char *base;
int nel;
int width;
int (*compar)();

DESCRIPTION

Qsort is an implementation of the quicker-sort algorithm.  The first argument is a pointer to the base of the data; the second is the number of elements; the third is the width of an element in bytes; the last is the name of the comparison routine to be called with two arguments which are pointers to the elements being compared. 

The routine must return an integer less than, equal to, or greater than 0 according as the first argument is to be considered less than, equal to, or greater than the second. 

EXAMPLE

struct entry {
char    *name;
intflags;
};
 main()
{
struct entry hp[100];

for (i = 0; i < count; i++ {
/* fill the structure with the name and flags */
.
.
.
}
qsort(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.  This example was taken from diffdir. 

SEE ALSO

sort(1)

7th Edition

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