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;
}
STL set使用例子的更多相关文章
- stl学习记录(2)
#include <iostream> #include <utility> #include <tuple> #include <complex> # ...
- Inversion Sequence(csu 1555)
Description For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence w ...
- C++0x,std::move和std::forward解析
1.std::move 1.1std::move是如何定义的 template<typename _Tp> constexpr typename std::remove_reference ...
- c/c++ 模板与STL小例子系列<三> traits
c/c++ 模板与STL小例子系列 traits 对这个概念,还是处于懵逼的状态,初步体会就是,为了解决类型之间的转换问题. 从一个类型为A的指针,转化到类型为B的指针,中间需要用void*来作为中介 ...
- c/c++ 模板与STL小例子系列<二> 模板类与友元函数
c/c++ 模板与STL小例子系列 模板类与友元函数 比如某个类是个模板类D,有个需求是需要重载D的operator<<函数,这时就需要用到友元. 实现这样的友元需要3个必要步骤 1,在模 ...
- c/c++ 模板与STL小例子系列<一 >自建Array数组
c/c++ 模板与STL小例子系列 自建Array数组 自建的Array数组,提供如下对外接口 方法 功能描述 Array() 无参数构造方法,构造元素个数为模板参数个的数组 Array(int le ...
- 【C++ STL编程】queue小例子
STL是标准化组件,现在已经是C++的一部分,因此不用额外安装什么. #include <queue> #include <iostream> using namespace ...
- C++STL之Vector向量详解,用法和例子 一起学习 一起加油
C++ STL之vector用法总结 1 ...
- c++ STL库deque和vector的例子
头文件wuyong.h: #pragma once #include<iostream> #include<vector> #include<deque> #inc ...
随机推荐
- SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)之间区别
http://m.blog.csdn.net/article/details?id=52795914#0-qzone-1-52202-d020d2d2a4e8d1a374a433f596ad1440
- 获取ORACLE数据库的构建信息
首先连接到数据库,获取ORACLE数据库的基本信息: C:\USERS\ADMINISTRATOR>SQLPLUS/NOLOG SQL*PLUS: RELEASE 10.2.0.3.0 - PR ...
- USB
[一].USB(Universal Serial Bus):是通用串行总线的缩写,具有方便易用,动态分配带宽,容错性优越和高性价比等特点. USB接口设备结构分:USB Host(主机)和USB De ...
- sublime Text 2 配置以及 Python环境搭建
在搭建Python环境前,先设置好Sublime Text 2的环境. 一.Sublime Text 2配置: 1.离线安装: Perferences-->Browser Packages -- ...
- C 语言中的优先级
先看一段代码: /********************************************************************* * @fn bdAddr2Str * * ...
- [Thinking in Java]这些必须先了解
2.基本概念和认识 2.1 Java引用 Java中一切皆是对象,一切对象实例的标识符号(对象名称)都只是对象的引用. 2.2 对象的创建 通过new关键字创建,但是要注意基础类型和String类型的 ...
- js动态更改对象属性值的方法
下面代码,替换属性名称包含date的属性中的T为空格. for (var o in data) { //console.info(eval("d ...
- android studio 插件
引用于:http://www.zhihu.com/question/28026027 adb-idea 支持直接在AS面板中进行ADB操作,个人觉得太实用,上面有哥们已提及,这里再介绍下: Unins ...
- asp.net 自定义控件 嵌入资源文件 备忘
要想在自定义用户控件中嵌入资源,从以下几个步骤入手: 1.在AssemblyInfo.cs中注册资源,文件夹层级用点隔开.例如: [assembly: System.Web.UI.WebResourc ...
- kvm
硬件,os,内核模块,用户空间工具,命令行具体参数,日志 [root@localhost ~]# yum install pciutils [root@localhost ~]# lscpu;lspc ...