zoukankan      html  css  js  c++  java
  • STL set使用例子

    #include<iostream>
    #include<set>
    using namespace std;

    #include<stdlib.h>

    #define random rand()

    class Edge
    {
    private:
    float errorMetric;
    public:
    float getErrorMetric() const {return errorMetric;}
    Edge(float error):errorMetric(error){}
    };

    struct lsEdge
    {
    bool operator() (const Edge& e1, const Edge& e2)
    {
    if(e1.getErrorMetric()<e2.getErrorMetric()) return true;
    else return false;
    }

    bool operator() (const Edge* e1, const Edge* e2)
    {
    if(e1->getErrorMetric()<e2->getErrorMetric()) return true;
    else return false;
    }
    };

    typedef set<Edge,lsEdge> EdgeSet;
    typedef set<Edge*,lsEdge> EdgePSet;
    int main()
    {
    EdgeSet es;
    for(int i=0;i<10;i++)
    {
    Edge e(i%2 + random);
    es.insert(e);
    }

    EdgeSet::iterator it = es.begin();
    for(it;it!=es.end();it++)
    {
    cout<<(*it).getErrorMetric()<<endl;
    }
    cout<<"-----------"<<endl;
    EdgePSet eps;
    for(int i=0;i<10;i++)
    {
    Edge * e = new Edge(random);
    eps.insert(e);
    }
    for(EdgePSet::iterator it=eps.begin();it!=eps.end();it++)
    {
    cout<<const_cast<Edge*>(*it)->getErrorMetric()<<endl;
    }

    return 0;
    }

  • 相关阅读:
    re.sub函数的深入了解
    xpath
    改变评分查询
    Boolean Query
    固定分数查询
    Unicode编码的原型
    java中基本类型占用字节数
    Java Socket网络编程的经典例子(转)
    (转)工厂模式
    (转)java垃圾回收机制
  • 原文地址:https://www.cnblogs.com/infiniti/p/5419535.html
Copyright © 2011-2022 走看看