Skip to content

结构体

1.1 构造函数

struct node{
    int data;
    string str;
    char x;
    //自己写的初始化函数
    void init(int a, string b, char c){
        this->data = a;
        this->str = b;
        this->x = c;
    }
    node() :x(), str(), data(){}
    node(int a, string b, char c) :x(c), str(b), data(a){}
};

1.2 重置运算符

//1.this写法
struct point
{
    int elem;
    bool operator==(const point b) const
    {
        return this->elem == b.elem;
    }
    bool operator!=(const point b) const
    {
        return this->elem != b.elem;
    }
    bool operator<=(const point b) const
    {
        return this->elem <= b.elem;
    }
    bool operator<(const point b) const
    {
        return this->elem < b.elem;
    }
    bool operator>=(const point b) const
    {
        return this->elem >= b.elem;
    }
    bool operator>(const point b) const
    {
        return this->elem > b.elem;
    }
};
//2.&写法
struct node{
    int dis,pos;
  bool operator <(const node &x)const{
     return x.dis<dis; 
  }
};
* 应用:dijkstra堆优化
struct node{
    int dis,pos;
  bool operator <(const node &x)const{
     return x.dis<dis; 
  }
  bool
    node(int d,int x){
         dis=d;pos=x;
   }
};