如何在C 对向量的第二个元素上执行较低的操作
How to perform a lower_bound operation on the second elements of a vector of pairs in C++?
一个人可以将所有 v[i].second
元素复制到新向量,然后在新向量上进行lower_bound
操作,并且作为我们所搜索的特定值的位置,在这两个方面都是相同的向量,因此可以做到合理。但是,如果矢量有很多元素,那么复制将是昂贵的。
因此,如果可能的话,我想知道在vector<pair<int,int>>
类型的容器上执行lower_bound
操作的语法(特别是在向量的第二个元素上(。
int myValue = 42; // value to search for.
std::lower_bound(myVector.begin(), myVector.end(), myValue,
[](const pair<int,int>& a, int b) {
return a.second < b;
});
这假设向量由element.second
分类。
相关文章:
- 按下Arduino按钮后,如何在C#应用程序上执行操作
- 是否可以访问类数据成员并在析构函数中对它们执行操作?
- 如何让派生类在调用基类之前执行操作?
- CListCtrl 根据选定的行值执行操作
- 在服务器上执行操作的正确和 REST 方式?
- 是否可以拦截/检测关闭 PC 并首先执行操作的请求?
- 如何有效地使用 std::async 对指针数组执行操作
- 无法对套接字执行操作,因为系统缺少足够的缓冲区空间或队列已满
- 递归推动POP POSTFIX计算器无法正确执行操作,只需将最后一个数字作为结果
- QListWidgetItem 当按钮单击时执行操作
- 为什么C++没有简洁的语法允许在不定义计数器的情况下多次执行操作?
- 如何在标准库C/C++函数中进行gdb单步执行操作
- 如何对 n 个字符串执行操作,然后在C++中打印它们
- 从文件中读取运算符并执行操作C++
- 使用重载运算符在函数调用时执行操作
- 您如何选择在opencv-dnn上执行操作的设备
- 如何使用BoostSpirit.Qi增量解析(并对其执行操作)大文件
- 在remove_if删除元素之前,我可以滥用谓词对元素执行操作吗
- 在使用Qt修改任何复选框状态时执行操作
- 是否可以在不使用任何头文件的情况下在C++中执行I/O操作