#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. Dos学习笔记(3)attrib命令

    今天和昨天一直在摸索这个命令觉得这个命令为什么改变不了文件夹的属性, 因为我试着用attrib +r /s 去修改子文件夹的时候发现没用,然后如果输入 attrib +r /d 又提示说/d需要和/s ...

  2. 【Gerrit】Gerrit cmd query (gerrit命令行查询change信息)

    本文仅展现个人使用情况和理解,英文原址:https://review.openstack.org/Documentation/cmd-query.html 基本使用格式: ssh -p <por ...

  3. System.DateUtils 4. IsValidDateTime... 有效时间判断

    编译版本:Delphi XE7 function IsValidDate(const AYear, AMonth, ADay: Word): Boolean;function IsValidTime( ...

  4. 【P1379】天才的约数和

    来自GDOI2007,原题已不可考-- 又自己做出来了好开心,找特殊性是个关键的切入点 原题: 这天周航遇到了靳泽旭. 周航:"我是天才!" 靳泽旭:"你为什么是天才?& ...

  5. sql中的跨库查询

    在sql查询时,需要关联2个服务器上的不同数据库,只需要在所需查询的表名前加上服务器地址即可. 例如:在 192.168.0.15,8020的db110库 和 192.168.0.150,8082的d ...

  6. linux 下如何抓取HTTP流量包(httpry)

    基于某些原因你需要嗅探HTTP Web流量(即HTTP请求和响应).例如,你可能会测试Web服务器的性能,或者x奥uy调试Web应用程序或RESTful服务 ,又或者试图解决PAC(代理自动配置)问题 ...

  7. NPOI读取Excel

    项目环境:Webform framework4.0 dll版本:NPOI2.0  dotnet2.0版本 这两天要做个excel导入的功能,想到以前用过NPOI,感觉很给力,今天写了个DEMO,写的时 ...

  8. android studio 插件

    引用于:http://www.zhihu.com/question/28026027 adb-idea 支持直接在AS面板中进行ADB操作,个人觉得太实用,上面有哥们已提及,这里再介绍下: Unins ...

  9. UIAlertView和UIActivityIndicatorView的使用

    UIAlertView用来显示一个对话框,可以设置对话框的标题.文案.按钮的个数和文案,也可以通过实现delegate来监听按钮的的点击操作. 使用UIAlertView时需要注意: self.ale ...

  10. Windows下: RubyMine + Ruby On Rails + mysql 搭建开发环境

    最近在接手一个手机项目.在搭建环境的过程中,遇到了一些问题,在下文中已做记录,并奉上个人的解决方案. 开发环境 win2003 ;  JetBrains RubyMine6.3.3 1.  下载最新版 ...