系统接口函数详解
1. bsearch( ) 函数
1.1 函数概述
bsearch()
函数用于在已排序的表中进行二分查找。其原型如下:
#include <stdlib.h>
void *bsearch(const void *key, const void *base, size_t nel,
size_t width, int (*compar)(const void *, const void *));
1.2 参数说明
参数 | 说明 |
---|---|
key |
指向要查找的对象的指针 |
base |
指向数组初始元素的指针 |
nel |
数组中元素的数量 |
width |
数组中每个元素的大小 |
compar |
比较函数的指针 |