首页 > 其他 > 详细

upper_bound()与lower_bound()使用方法

时间:2014-09-10 19:33:01      阅读:366      评论:0      收藏:0      [点我收藏+]

upper_bound()与lower_bound()使用方法

 
 
#include<iostream>
#include <algorithm>     //必须包含的头文件
using namespace std;

int main(){
 int point[10] = {2,3,7,7,8};
 int tmp = upper_bound(point, point + 5, 7) -point;     //按从小到大,7最多能插入数组point的哪个位置
 printf("%d\n",tmp);
 tmp = lower_bound(point, point + 5, 7) -point;           //按从小到大,7最少能插入数组point的哪个位置
 printf("%d\n",tmp);
 return 0;
}

output:

4

2

lower_bound:

                返回>=对象的第一个位置,lower_bound(2)=3, lower_bound(3)=3
                     目标对象存在即为目标对象的位置,不存在则为后一个位置.
upper_bound:

                  返回>对象的第一个位置, upper_bound(2)=3,upper_bound(3)=4
                    无论是否存在都为后一个位置.

upper_bound()与lower_bound()使用方法

原文:http://blog.csdn.net/u013514722/article/details/39184653

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!