Deque和Vector类似,只不过deque头尾都开放,能够在头尾进行快速插入和删除操作

DequeTest.cpp

#include <iostream>
#include <deque>
#include <string>
#include <algorithm>
#include <iterator>
#include "DequeTest.h" using namespace std; void DequeTest::simpleOperation()
{
// create empty deque of strings
deque<string> coll; // insert several elements
coll.assign(, string("string"));
coll.push_back("last string");
coll.push_front("first string"); // print elements separated by newlines
copy(coll.cbegin(), coll.cend(),
ostream_iterator<string>(cout, "\n"));
cout << endl; // remove first and last element
coll.pop_front();
coll.pop_back(); // insert "another" into every element but the first
for (unsigned i = ; i<coll.size(); ++i) {
coll[i] = "another " + coll[i];
} // change size to four elements
coll.resize(, "resized string"); // print elements separated by newlines
copy(coll.cbegin(), coll.cend(),
ostream_iterator<string>(cout, "\n"));
} void DequeTest::run()
{
printStart("simpleOperation()");
simpleOperation();
printEnd("simpleOperation()");
}

运行结果:

---------------- simpleOperation(): Run Start ----------------
first string
string
string
string
last string

string
another string
another string
resized string
---------------- simpleOperation(): Run End ----------------

STL - 容器 - Deque的更多相关文章

  1. 带你深入理解STL之Deque容器

    在介绍STL的deque的容器之前,我们先来总结一下vector和list的优缺点.vector在内存中是分配一段连续的内存空间进行存储,其迭代器采用原生指针即可,因此其支持随机访问和存储,支持下标操 ...

  2. STL容器 vector,list,deque 性能比较

    C++的STL模板库中提供了3种容器类:vector,list,deque对于这三种容器,在觉得好用的同时,经常会让我们困惑应该选择哪一种来实现我们的逻辑.在少量数据操作的程序中随便哪一种用起来感觉差 ...

  3. [转]STL之deque容器详解

    Deque 容器 deque容器是C++标准模版库(STL,Standard Template Library)中的部分内容.deque容器类与vector类似,支持随机访问和快速插入删除,它在容器中 ...

  4. STL——容器(deque) 元素的存取&迭代器

    1. deque 的数据存取 这个部分和 vector 几乎一样 第一  使用下标操作 dequeName[0] = 100; //小心越界 第二  使用at 方法 如: dequeName.at(2 ...

  5. STL容器删除元素的陷阱

    今天看Scott Meyers大师的stl的用法,看到了我前段时间犯的一个错误,发现我写的代码和他提到错误代码几乎一模一样,有关stl容器删除元素的问题,错误的代码如下:std::vector< ...

  6. STL容器迭代器失效分析

    连续内存序列容器(vector, string, deque) 对于连续内存序列STL容器,例如vector,string,deque,删除当前iterator会使得后面所有的iterator都失效, ...

  7. STL容器的适用情况

     转自http://hsw625728.blog.163.com/blog/static/3957072820091116114655254/ ly; mso-default-props:yes; m ...

  8. STL容器的遍历删除

    STL容器的遍历删除 今天在对截包程序的HashTable中加入计时机制时,碰到这个问题.对hash_map中的每个项加入时间后,用查询函数遍历hash_map,以删除掉那些在表存留时间比某个阈值长的 ...

  9. STL容器与配接器

    STL容器包括顺序容器.关联容器.无序关联容器 STL配接器包括容器配接器.函数配接器 顺序容器: vector                             行为类似于数组,但可以根据要求 ...

随机推荐

  1. 【洛谷】4317:花神的数论题【数位DP】

    P4317 花神的数论题 题目背景 众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦. 题目描述 话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我 ...

  2. bzoj 1337 最小圆覆盖

    /************************************************************** Problem: 1337 User: idy002 Language: ...

  3. Codeforces Round #222 (Div. 1) C. Captains Mode 状压

    C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer ...

  4. Mac下使用ABTestingGateway快速搭建灰度网关

    ABTestingGateway简介 ABTestingGateway 是新浪开源的一个可以动态设置分流策略的灰度发布系统,工作在7层,基于nginx和ngx-lua开发,使用 redis 作为分流策 ...

  5. SecureCRT远程连接Linux服务器及相关配置

    这里的连接采用的是SSH2协议,关于SSH2协议可百度 一.连接不上可能的原因 1)服务器防火墙iptables /etc/init.d/iptables stop 2)SSH服务有问题 3)客户端到 ...

  6. %( $# > 1 %? if (tid() in trace) %) 是什么意思

    http://blog.csdn.net/sunnybeike/article/details/7769663 http://blog.163.com/digoal@126/blog/static/1 ...

  7. erlang debug

    http://www.cnblogs.com/goldli/archive/2011/03/08/1976998.html erlang 模块文件 helloworld.erl 文件内容: -modu ...

  8. Vue2.1.7源码学习

    原本文章的名字叫做<源码解析>,不过后来想想,还是用“源码学习”来的合适一点,在没有彻底掌握源码中的每一个字母之前,“解析”就有点标题党了.建议在看这篇文章之前,最好打开2.1.7的源码对 ...

  9. 算法:图(Graph)的遍历、最小生成树和拓扑排序

    背景 不同的数据结构有不同的用途,像:数组.链表.队列.栈多数是用来做为基本的工具使用,二叉树多用来作为已排序元素列表的存储,B 树用在存储中,本文介绍的 Graph 多数是为了解决现实问题(说到底, ...

  10. 转: Go -- 单例

    最近在学习Golang,想着可以就以前的知识做一些串通,加上了解到go语言也是面向对象编程语言之后.在最近的开发过程中,我碰到一个问题,要用go语言实现单例模式.本着“天下知识,同根同源”(我瞎掰的~ ...