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 ...
随机推荐
- 原生select默认显示为空胡fish覅神农大丰今年圣诞节奋笔疾书发撒可交付你说的尽快发那段时间南方大厦尽可能放你的所发生的你富家大室耐腐蚀的看法呢尽快发你上课积啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊撒啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊分你束带结发你看
下拉框默认为空: <select> <option value="" class="blank"></option> < ...
- 集成Visual Studio/MSBuild的开发/发布流程和 FIS3
谁不想让自己的网站速度更快?为此需要多方面的优化,但优化又会增加开发工作量.Fis3 是很不错的前端优化工具,能够让前端的优化变得自动方便,解决前述问题.Fis3是百度开发的,开源的,在国内比较六流行 ...
- MongoDB学习笔记五:聚合
『count』count是最简单的聚合工具,返回集合中的文档数量:> db.foo.count()0> db.foo.insert({"x" : 1})> db. ...
- Jquery cxColor 示例演示
今天第一次自己做调色板调用,看了半天官方的例子愣是没看懂,唉,码农老矣,尚能码否? 经过对官方下载的示例一删一浏览终于弄出来了,这么简单的东西,官方的Demo逼格也太高了 上代码: <!DOCT ...
- Python range() xrange()
range 前面小节已经说明了,range([start,] stop[, step]),根据start与stop指定的范围以及step设定的步长,生成一个序列. xrange用法与 range 完全 ...
- Centos7的安装、Docker1.12.3的安装,以及Docker Swarm集群的简单实例
目录 [TOC] 1.环境准备 本文中的案例会有四台机器,他们的Host和IP地址如下 c1 -> 10.0.0.31 c2 -> 10.0.0.32 c3 -> 10.0.0. ...
- getview不执行
<FrameLayout android:layout_width="match_parent" android:layout_height="match_pare ...
- Imagenet tools install on windows
1.find the pyrcc4.exe path: C:\Anaconda2\Library\bin 2.cmd: pyrcc4 -o resources.py resources.qrc 3.a ...
- 配置文件的生成,关于“make menuconfig”
之前学习嵌入式的时候从来没有注意过内核源文件下配置文件的生成(都是跟着老师的步骤直接复制过来修改成.config),其实意思也差不多,只是我没有细想其所以然: 编译内核的过程中,配置文件生成过程,A. ...
- oracle 科普
Schem定义 A schema is a collection of database objects (used by a user.). Schema objects are the logic ...