小编Nim*_*mra的帖子

为什么我们必须重载'<'运算符才能使用is_permutation并包含算法

我有一个向量,它拥有一个点向量,这是一个具有x和ay坐标的类。我基本上必须从向量中删除所有排列和子集。为此,我利用算法包括和is_permutation

我已经重载了'=='运算符,因此我们为什么需要它很有意义。但是除非我重载'<'运算符,否则这两种算法将不起作用。

这是我的重点课:

class Point{

private:    
    int x;
    int y;
public:
    Point(){
        x=0;
        y=0;
    }
    Point(int xx, int yy){
        x=xx;
        y=yy;
    }

    double getSlope(Point p){
        if(this->x!=p.x && this->y!=p.y){
            return (double)(double(this->y-p.y)/double(this->x-p.x));
        }else if(this->x==p.x){
            return INT_MAX;
        }else{
            return INT_MIN;
        }
    }   
    void print(){
        cout<<"(" <<x<<","<<y<<")";
    }
    bool operator == (Point &p){
    if(this->x==p.x && this->y==p.y )
        return true;
    else
        return false;
    }
    bool operator < (Point &p){
        cout<<"\nin the < operator\n";
    if(this->x < p.x && this->y < p.y )
        return true;
    else
        return …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm stl

1
推荐指数
1
解决办法
68
查看次数

标签 统计

algorithm ×1

c++ ×1

stl ×1