Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

lsearch(3C)

qsort(3C)

BSEARCH(3C)

NAME

bsearch − binary search

SYNOPSIS

char ∗bsearch (key, base, nel, width, compar)
char ∗key;
char ∗base;
int nel, width;
int (∗compar)();

DESCRIPTION

Bsearch is a binary search routine generalized from Knuth (6.2.1) Algorithm B.  It returns a pointer into a table indicating the location at which a datum may be found.  The table must be previously sorted in increasing order.  The first argument is a pointer to the datum to be located in the table.  The second argument is a pointer to the base of the table.  The third is the number of elements in the table.  The fourth is the width of an element in bytes.  The last is the name of the comparison routine.  It is 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. 

DIAGNOSTICS

Zero is returned if the key can not be found in the table. 

SEE ALSO

lsearch(3C), qsort(3C). 

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