lower_bound和upper_bound的用法

来源:互联网 发布:好用的电磁炉推荐 知乎 编辑:程序博客网 时间:2024/05/23 01:26
#include <iostream>
#include <algorithm>//必须包含的头文件
using namespace std;
int main(){
 int point[10] = {1,3,7,7,9};

 int tmp = upper_bound(point, point + 5, 7) - point;//按从小到大,

最后一个小于等于7点位置

 printf("%d\n",tmp);

 tmp = lower_bound(point, point + 5, 7) - point;////按从小到大,

最后一个小于7的位置

 printf("%d\n",tmp);
 return 0;
}
output:
4
2