lower_bound / upper_bound 演示

随便写个代码演示一下

vector<int> a = {1,2,3,3,5,5,5,5,5,5,5,5,5,6,7};
cout << "lower_bound(5) index=" << lower_bound(a.begin(),a.end(),5)-a.begin() << ",value=" << *lower_bound(a.begin(),a.end(),5) << endl;
cout << "upper_bound(5) index=" << upper_bound(a.begin(),a.end(),5)-a.begin()  << ",value=" <<  *upper_bound(a.begin(),a.end(),5) << endl;
cout << "lower_bound(4) index=" << lower_bound(a.begin(),a.end(),4)-a.begin() << ",upper_bound(4) index=" << upper_bound(a.begin(),a.end(),4)-a.begin()  << endl;

结果

posted @ 2023-11-02 19:21  传说中的水牛  阅读(3)  评论(0编辑  收藏  举报