bsearch.3
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 3 代码 · 共 62 行
3
62 行
.\" SCCSID: @(#)bsearch.3 8.1 9/11/90.TH bsearch 3 .SH Namebsearch \- binary search a sorted table.SH Syntax.nf.B #include <stdlib.h>.PP.B "void *bsearch (\fIkey\fP, \fIbase\fP, \fInel\fP, sizeof (*\fIkey\fP), \fIcompar\fP)".B "void *\fIkey, *base\fP;.br.B size_t \fInel\fP;.B int (*\fIcompar\fP)\^( )\^;.fi.SH Description.NXR "bsearch subroutine".NXR "bsearch subroutine" "tsearch subroutine".NXR "binary search routine"The.PN bsearchsubroutineis a binary search routine generalized from Knuth (6.2.1) Algorithm B.It returns a pointer into a table indicating wherea datum may be found.The table must be previously sorted in increasing orderaccording to a provided comparison function.The.I key\^points to the datum to be sought in the table.The.I base\^points to the element at the base of the table.The.I nel\^is the number of elements in the table.The.I compar\^is the name of the comparison function,which is called with two arguments that pointto the elements being compared.The function must returnan integer less than, equal to, or greater than zeroaccording to whether the first argument is to be consideredless than, equal to, or greater than the second..SH DiagnosticsA NULLpointer is returned if the key cannot be found in the table..SS NotesThe pointers to the key and theelement at the base of the table should beof type pointer-to-element,and cast to type pointer-to-character..PPThe comparison function need not compare every byte,so arbitrary data may be contained in the elements in addition to the valuesbeing compared..PPAlthough declared as type pointer-to-character,the value returned should be cast into type pointer-to-element..SH See Alsohsearch(3), lsearch(3), qsort(3), tsearch(3)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?