#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;
}

STL set使用例子的更多相关文章

  1. stl学习记录(2)

    #include <iostream> #include <utility> #include <tuple> #include <complex> # ...

  2. Inversion Sequence(csu 1555)

    Description For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence w ...

  3. C++0x,std::move和std::forward解析

    1.std::move 1.1std::move是如何定义的 template<typename _Tp> constexpr typename std::remove_reference ...

  4. c/c++ 模板与STL小例子系列<三> traits

    c/c++ 模板与STL小例子系列 traits 对这个概念,还是处于懵逼的状态,初步体会就是,为了解决类型之间的转换问题. 从一个类型为A的指针,转化到类型为B的指针,中间需要用void*来作为中介 ...

  5. c/c++ 模板与STL小例子系列<二> 模板类与友元函数

    c/c++ 模板与STL小例子系列 模板类与友元函数 比如某个类是个模板类D,有个需求是需要重载D的operator<<函数,这时就需要用到友元. 实现这样的友元需要3个必要步骤 1,在模 ...

  6. c/c++ 模板与STL小例子系列<一 >自建Array数组

    c/c++ 模板与STL小例子系列 自建Array数组 自建的Array数组,提供如下对外接口 方法 功能描述 Array() 无参数构造方法,构造元素个数为模板参数个的数组 Array(int le ...

  7. 【C++ STL编程】queue小例子

    STL是标准化组件,现在已经是C++的一部分,因此不用额外安装什么. #include <queue> #include <iostream> using namespace ...

  8. C++STL之Vector向量详解,用法和例子 一起学习 一起加油

                                                                                    C++ STL之vector用法总结 1 ...

  9. c++ STL库deque和vector的例子

    头文件wuyong.h: #pragma once #include<iostream> #include<vector> #include<deque> #inc ...

随机推荐

  1. Python实例4

    4.输入某年某月某日,判断这一天是这一年的第几天? 正解: 源码:

  2. php部分---单文件上传的封装类

    <?php $fileinfo=$_FILES["myfile"]; function uploadfile($fileinfo,$allowext=array('jpeg' ...

  3. 关于Ubuntu共享文件夹的设置

    一.Xshell连接虚拟机(先关闭虚拟机的防火墙) sudo apt-get install openssh-serve sudo ufw disable sudo ufw allow 22 二.虚拟 ...

  4. MIT JOS学习笔记01:环境配置、Boot Loader(2016.10.22)

    未经许可谢绝以任何形式对本文内容进行转载! 一.环境配置 关于MIT课程中使用的JOS的配置教程网上已经有很多了,在这里就不做介绍,个人使用的是Ubuntu 16.04 + qemu.另注,本文章中贴 ...

  5. android dialog 有关token的问题

    android中的dialog显示一般是显示在宿主context里面,但context有几种模式,我今天遇到问题就是在BroadcastReceiver广播里面构造对话框后显示出现的问题:androi ...

  6. 如何将自己的windows设置为mysql服务器

    1.安装mysql 服务器 2.创建超级用户,即 用户管理 mysql>use mysql; 查看 mysql> select host,user,password from user ; ...

  7. svn提交报e200007错误

    org.apache.subversion.javahl.ClientException: svn: E200007: Commit failed异常解决,svncommitfailed 首先2分钟前 ...

  8. 集群工具ansible使用方法

    ansible简介 ansible是与puppet.saltstack类似的集群管理工具,其优点是仅需要ssh和Python即可使用,而不像puppet.saltstack那样都需要客户端.与pupp ...

  9. setTimeout()与setInterval()

    一.setTimeout与setInterval的用法(http://www.css88.com/archives/5804) setTimeout是超时调用,javascript是一个单线程的解析器 ...

  10. TCP和UDP之间的区别和联系

    面向连接的TCP TCP(Transmission Control Protocol,传输控制协议)是基于连接的协议,也就是说,在正式收发数据前,必须和对方建立可靠的连接.一个TCP连接必须要经过三次 ...