zoukankan      html  css  js  c++  java
  • 重载运算符-operator

    先看段代码:

    struct node
    {
        friend bool operator< (node n1, node n2){   // 优先取最小的,它与下面的 // 是等价的
            return n1.e > n2.e;
        }
       //bool operator< (const node &r)const{ // <是重载运算符,不是普通的小于
        //    return s > r.s;
        //} int s, e; node(int a, int b){ s = a; e = b; } };
    //bool operator< (const node& a, const node& b){ // 其也是等价的
    //    return a.s > b.s;
    //} int main() { priority_queue<node>que; // 此优先队列实现的是取最小的 que.push(node(1, 10)); que.push(node(5, 50)); que.push(node(2, 20)); while(!que.empty()){ printf("%d ", que.top().s); que.pop(); } return 0; }  

     在结构体中

    struct node
    {
        int s, e;
        node(int _v , int _c ):s(_v),e(_c){} // 这样写是可以进行附初值
                                            // 同理与下面的 // 是等价的 
        //node(int a, int b){
            //s = a;
            //e = b;
        //}
    };
    
    int main() {
        queue<node>que;
        
        que.push(node(1, 10));
        que.push(node(5, 50));
        que.push(node(2, 20));
        //while(!que.empty()){
            //printf("%d
    ", que.top().s);
            //que.pop();
        //}
        while(!que.empty()){
            printf("%d %d
    ", que.front().s, que.front().e);
            que.pop();
        }
        return 0;
    }
    
    东北日出西边雨 道是无情却有情
  • 相关阅读:
    第八周作业
    第七周上机作业2
    神经网络基础
    [网鼎杯 2020 青龙组]AreUSerialz
    BJDCTF 2nd old-hack
    php反序列化漏洞学习
    CTFHUB-HTTP协议
    ctfhub-密码口令
    CTFHUB-信息泄漏
    buuctf-[BJDCTF 2nd]elementmaster
  • 原文地址:https://www.cnblogs.com/ccut-ry/p/7774725.html
Copyright © 2011-2022 走看看