利用二分查找的方法在一个排好序的数组中进行查找的。

作用:

lower_bound( begin,end,num):从数组的begin位置到end-1位置二分查找第一个大于或等于num的数字,找到返回该数字的地址,不存在则返回end。通过返回的地址减去起始地址begin,得到找到数字在数组中的下标

lower_bound(a,a+n,num)-a

upper_bound( begin,end,num):从数组的begin位置到end-1位置二分查找第一个大于num的数字,找到返回该数字的地址,不存在则返回end。通过返回的地址减去起始地址begin,得到找到数字在数组中的下标。

查找之前记得排序sort

upper_bound和lower_bound

相关文章:

  • 2021-07-30
  • 2022-01-13
  • 2021-07-24
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-07
  • 2021-12-14
  • 2021-06-30
  • 2022-12-23
  • 2022-01-05
  • 2021-12-09
  • 2021-09-23
相关资源
相似解决方案