STL - 容器 - UnorderedSet(一)
一些简单操作
UnorderedSetTest.cpp
#include <unordered_set>
#include <numeric>
#include "../../Core/print.hpp"
#include "UnorderedSetTest.h" using namespace std; void UnorderedSetTest::simpleOperation()
{
// create and initialize unordered set
unordered_set<int> coll = { , , , , , , , , , }; // print elements
// - elements are in arbitrary order
PRINT_ELEMENTS(coll); // insert some additional elements
// - might cause rehashing and create different order
coll.insert({ -, , , -, , , , });
PRINT_ELEMENTS(coll); // remove element with specific value
coll.erase(); // insert sum of all existing values
coll.insert(accumulate(coll.begin(), coll.end(), ));
PRINT_ELEMENTS(coll); // check if value 19 is in the set
if (coll.find() != coll.end())
{
cout << "19 is available" << endl;
} // remove all negative values
unordered_set<int>::iterator pos;
for (pos = coll.begin(); pos != coll.end();)
{
if (*pos < ) {
pos = coll.erase(pos);
}
else {
++pos;
}
} PRINT_ELEMENTS(coll);
} void UnorderedSetTest::run()
{
printStart("simpleOperation()");
simpleOperation();
printEnd("simpleOperation()");
}
运行结果:
---------------- simpleOperation(): Run Start ----------------
17 1 2 19 11 3 77 13 5 7
17 1 2 19 11 3 77 13 5 7 -7 33 -11
17 1 2 19 11 3 77 13 5 7 -7 -11 137
19 is available
17 1 2 19 11 3 77 13 5 7 137
---------------- simpleOperation(): Run End ----------------
STL - 容器 - UnorderedSet(一)的更多相关文章
- STL容器
啦啦啦,今天听啦高年级学长讲的STL容器啦,发现有好多东西还是有必要记载的,毕竟学长是身经百战的,他在参加各种比赛的时候积累的经验可不是一天两天就能学来的,那个可是炒鸡有价值的啊,啊啊啊啊啊 #inc ...
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
c++ stl集合set介绍 c++ stl集合(Set)是一种包含已排序对象的关联容器.set/multiset会根据待定的排序准则,自动将元素排序.两者不同在于前者不允许元素重复,而后者允许. 1 ...
- STL容器删除元素的陷阱
今天看Scott Meyers大师的stl的用法,看到了我前段时间犯的一个错误,发现我写的代码和他提到错误代码几乎一模一样,有关stl容器删除元素的问题,错误的代码如下:std::vector< ...
- 【转】c++中Vector等STL容器的自定义排序
如果要自己定义STL容器的元素类最好满足STL容器对元素的要求 必须要求: 1.Copy构造函数 2.赋值=操作符 3.能够销毁对象的析构函数 另外: 1. ...
- GDB打印STL容器内容
GDB调试不能打印stl容器内容,下载此文件,将之保存为~/.gdbinit就可以使用打印命令了. 打印list用plist命令,打印vector用pvector,依此类推. (gdb) pvecto ...
- STL容器迭代器失效分析
连续内存序列容器(vector, string, deque) 对于连续内存序列STL容器,例如vector,string,deque,删除当前iterator会使得后面所有的iterator都失效, ...
- STL容器的适用情况
转自http://hsw625728.blog.163.com/blog/static/3957072820091116114655254/ ly; mso-default-props:yes; m ...
- STL容器的遍历删除
STL容器的遍历删除 今天在对截包程序的HashTable中加入计时机制时,碰到这个问题.对hash_map中的每个项加入时间后,用查询函数遍历hash_map,以删除掉那些在表存留时间比某个阈值长的 ...
- STL容器与配接器
STL容器包括顺序容器.关联容器.无序关联容器 STL配接器包括容器配接器.函数配接器 顺序容器: vector 行为类似于数组,但可以根据要求 ...
随机推荐
- Windows安装绿色版git管理软件GitStack 2.3.8
1.原来 GitStack 是安装在局域网的,为了更好开展工作,迁移到公网的服务器.(安全性未知) 2.公网服务器已经在运行一个 Apache 2.4 (占用80端口): 3.GitStack 2. ...
- wikioi 1068 乌龟棋
四维dp表示分别用了多少张卡后可以获得的最大分数 #include <cstdio> #include <cmath> #include <cstring> #in ...
- JavaScript中的callee与caller的区别
1.callee callee是对象的一个属性,该属性是一个指针,指向参数arguments对象的函数 作用:就是用来指向当前对象 返回正被执行的 Function 对象,也就是所指定的 Functi ...
- 解决MySQL建立连接问题,快速回收复用TCP的TIME_WAIT
最近同事遇到一个问题,使用python开发的工具在执行的时候无法和MySQL建立连接,其最直接的现象就是满篇的TIME_WAIT,最后通过调整tcp_timestamps参数问题得以解决,再次记录一下 ...
- Git_git的诞生
很多人都知道,Linus在1991年创建了开源的Linux,从此,Linux系统不断发展,已经成为最大的服务器系统软件了. Linus虽然创建了Linux,但Linux的壮大是靠全世界热心的志愿者参与 ...
- SPOJ 3267. D-query (主席树,查询区间有多少个不相同的数)
3267. D-query Problem code: DQUERY English Vietnamese Given a sequence of n numbers a1, a2, ..., an ...
- Clever Little Box 电缆组件 USB A 插座 至 USB B 插头
http://china.rs-online.com/web/p/usb-cable-assemblies/7244156/ 产品详细信息 USB3.0适配器 superspeed USB将提供10x ...
- 解析本内置Linux目录结构
使用声明:1.此版本采用官方原版ISO+俄罗斯HunterTik 的Debian包制作而成2.此IMG包未进行Crack,资源来源于网络,如果你下载的是Crack版,与原作者无关,请自行分辨.“就看人 ...
- Scheduled Jobs with Custom Clock Processes in Java with Quartz and RabbitMQ
原文地址: https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes-java-quartz-rabbit ...
- 【java】将字符串的首字母大写
工具方法: public static void main(String[] args) { System.out.println(upperCaseFirst("barer")) ...