Multiset Upper_bound和Lower_Bound不起作用

时间:2014-02-26 06:42:26

标签: c++ sorting upperbound

我正在解决一些几何问题,我不知道如何使用multiset处理一个奇怪的问题。 我必须计算具有共同点的圆对的数量。所以我使用扫描线算法来解决这个问题。当我在X轴上有不同的圆圈时,下边界和上边界完美无缺。但是,当我在y轴上有圆圈时 假设我有圈子: < 0,10>< 0,20>< 0,30>所有5个半径,mset在下限和上限返回一个NULL指针。

struct point{
    int x, y, pos,m;
    bool operator<(const point &p)const {
        return y<p.y;  };
};


  std::multiset<point>::iterator itlow,itup;
                itlow = mset.lower_bound (p[i]);// p is a vector of points
                itup = mset.upper_bound (p[i]);     // mset is a multiset of points
                // check the iterators
                if(itlow==mset.end())
                    printf("NULL\n");
                if(itup==mset.end())
                    printf("NULL\n");

我也尝试过这样改变我的算子

 bool operator<(const point &p1,const point &p2) {
        if(p1.y!=p2.y)
        return p1.y<p2.y; 
        else if (p1.x!=p2.x)
        return p1.x<p2.x;
        else if(p1.pos!=p2.pos)
        return p1.pos<p2.pos;
        else return p1.m>p2.m; };
它崩溃了。

0 个答案:

没有答案