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 ...
随机推荐
- 备忘DES带向量的加密和解密与DES简单加密与解密
package com.ego.util; import java.security.Key; import java.security.SecureRandom; import java.secur ...
- Hibernate配置log4j日志环境
1.准备所需的jar 说明:具体所使用的jar包的版本与你所使用的Hibernate版本有关,我用的是(hibernate-release-4.3.11.Final) <1>准备slf4j ...
- Java中类的数据成员的初始化顺序
对于单一类: 属性初始化 ---> 按顺序执行静态初始化块(只能操作静态属性) ---> 按顺序执行初始化块 ---> 构造方法 对于存在继承关系的类: 父类属性初始化 ---> ...
- Linux下得到毫秒级时间--C语言实现(转-度娘818)
Linux下得到毫秒级时间--C语言实现 原文链接: http://www.cnblogs.com/nwf5d/archive/2011/06/03/2071247.html #ifdef HAVE_ ...
- hadoop 集群跑的时候用到hbasejar 文件的引用问题
1. 创建软连接 ln -s /home/hadoop/bigdater/hbase-0.98.6-cdh5.3.6/conf/hbase-site.xml ./hbase-site.xml(记得这里 ...
- C语言实现最基本的回射服务器与客户端(服务器用TCP协议回射客户发来的消息)
话不多说,直接上干货,下面两个程序都是linux程序. server.c完整代码: #include <stdio.h>#include <string.h>#include ...
- u-boot-2010.09移植(A)
第一阶段 1.开发环境 系统:centOS6.5 linux版本:2.6.32 交叉编译器:buildroot-2012.08 以上工具已经准备好,具体安装步骤不再 ...
- unicode,ansi,utf-8,unicode big endian编码的区别
知乎--http://www.zhihu.com/question/23374078 http://wenku.baidu.com/view/cb9fe505cc17552707220865.html ...
- maven 环境搭建
1.maven环境搭建 1)下载maven,http://maven.apache.org/download.cgi,到本地解压,然后配置环境变量 MAVEN_HOME:D:\software\apa ...
- HTMLParser使用
htmlparser[1] 是一个纯的java写的html(标准通用标记语言下的一个应用)解析的库,它不依赖于其它的java库文件,主要用于改造或提取html.它能超高速解析html,而且不会出错.现 ...