lower_bound的重载已经结构体的如何用

可以参考下结构体里如何运用二分.
#include 

using namespace std;
struct node
{
    int x,y;
};
struct cmp1
{
    bool operator () (const node &a,const node &b) const {
        return a.x < b.x;
    }
};
int main()
{
    vectorpq;
    pq.push_back({1,3});
    pq.push_back({2,8});
    pq.push_back({4,3});
    node a;
    a.x = a.y = 3;
    vector::iterator it = lower_bound(begin(pq),end(pq),a,cmp1());
    cout << (*it).x << endl;
}


你可能感兴趣的:(lower_bound的重载已经结构体的如何用)