二分搜索函数 C/C++
二分搜索函数
C语言:bsearch()
C++:binary_search()
1.C语言:bsearch()
函数原型如下:
void* bsearch(
const void *key,
const void *ptr,
size_t count,
size_t size,
int (*comp)(const void*, const void*) );2.C++:binary_search()
binary_search(起始地址,结束地址,要查找的数值)
返回的是是否存在这么一个数,是一个bool值。3.C++扩展
lower_bound(起始地址,结束地址,要查找的数值)
lower_bound():返回大于或等于目标值的第一个位置
upper_bound(起始地址,结束地址,要查找的数值)
upper_bound():返回大于目标值的第一个位置参考资料:
https://blog.csdn.net/sinat_31608641/article/details/124975237
https://baijiahao.baidu.com/s?id=1793956676806508127&wfr=spider&for=pc 当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »