因此在实际使用时,如何选择这三个容器中哪一个,应根据你的需要而定,一般应遵循下面
的原则:
  1、如果你需要高效的随即存取,而不在乎插入和删除的效率,使用vector
  2、如果你需要大量的插入和删除,而不关心随即存取,则应使用list
  3、如果你需要随即存取,而且关心两端数据的插入和删除,则应使用deque。

MSDN:

1. Introduction

The STL vector class is a template class of sequence containers that arrange elements of a given type in a linear arrangement and allow fast random access to any element.They should be the preferred container for a sequence when random-access performance is at a premium.

2. Compare

vectors allow constant time insertions and deletions at the end of the sequence.

Inserting or deleting elements in the middle of a vector requires linear time.

The performance of the deque Class container is superior with respect to insertions and deletions at the beginning and end of a sequence.

The list Class container is superior with respect to insertions and deletions at any location within a sequence.

3. Reallocation

Vector reallocation occurs when a member function must increase the sequence contained in the vector object beyond its current storage capacity.

Other insertions and erasures may alter various storage addresses within the sequence.

In all such cases, iterators or references that point at altered portions of the sequence become invalid.

If no reallocation happens, only iterators and references before the insertion/deletion point remain valid.

vector list array deque的更多相关文章

  1. Namespace, string, vector and array

    1. Headers should not include using declaration Code inside headers ordinarily should not include us ...

  2. Vector, ArrayList, Array

    JAVA新手在使用JAVA的时候大概都会遇到这个问题: JAVA中的Array, ArrayList, Vector, List, LinkedList有什么样的区别?尤其是Vector, Array ...

  3. C++标准库分析总结(四)——<Vector、Array、Forward_list设计原则>

    本节主要总结标准库Vector和Array的设计方法和特性以及相关迭代器内部特征 1.Vector 1.1 Vector 内部实现 Vector是自增长的数组,其实在标准库中没有任何一种容器能原地扩充 ...

  4. vector以及array和数组

    //比较数组.vector.array #include <iostream> #include <vector> #include <array> #includ ...

  5. STL vector容器 和deque容器

    前言 STL是C++的框架,然后vector容器和deque容器又是STL的一部分... 这块的内容都是理解.概念为主,没什么捷径,希望读者能静下来记. 先来讲vector容器(单端动态数组) 1.v ...

  6. java三篇博客转载 详解-vector,stack,queue,deque

    博客一:转载自http://shmilyaw-hotmail-com.iteye.com/blog/1825171 java stack的详细实现分析 简介 我们最常用的数据结构之一大概就是stack ...

  7. 迭代器遍历列表 构造方法 constructor ArrayList Vector LinkedList Array List 时间复杂度

    package priceton; import java.io.IOException; import java.util.concurrent.CyclicBarrier; import java ...

  8. ArrayList、LinkedList、Vector、Array和HashMap、HashTable

    就 ArrayList 与 Vector 主要从二方面来说. 一.同步性:Vector 是线程安全的,也就是说是同步的,而ArrayList 是线程序不安全的,不是同步的 二.数据增长:当需要增长时, ...

  9. STL容器用法速查表:list,vector,stack,queue,deque,priority_queue,set,map

      list vector deque stack queue priority_queue set [unordered_set] map [unordered_map] multimap [uno ...

随机推荐

  1. vijos P1243 生产产品(单调队列+DP)

      P1243生产产品   描述 在经过一段时间的经营后,dd_engi的OI商店不满足于从别的供货商那里购买产 品放上货架,而要开始自己生产产品了!产品的生产需要M个步骤,每一个步骤都可以在N台机器 ...

  2. java迭代器demo

    package cn.aust.zyw.demo; import java.util.Iterator; /** * Created by zyw on 2016/2/16. * Iterator模式 ...

  3. android快捷简单的实现音乐播放器

    自己做了一个相对完整的音乐播放器,现在把播放模块提取出来,分享给大家.音乐播放器基本功能都实现了的,可能有些BUG,希望谅解. 播放器功能如下: 1.暂停,播放 2.拖动条实现,快进,快退 3.歌词同 ...

  4. Quartz的cronTrigger表达式

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...

  5. Java对XML文档的增删改查

    JAVA增删改查XML文件   最近总是需要进行xml的相关操作. 不免的要进行xml的读取修改等,于是上网搜索,加上自己的小改动,整合了下xml的常用操作. 读取XML配置文件 首先我们需要通过Do ...

  6. 【LeetCode】Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

  7. [PWA] 1. Intro to Service worker

    Service worker stays between our browser and noetwork requests. It can help to fetch data from cache ...

  8. PHP学习路径

    php学习大致可分为三个阶段: 第一阶段:基础知识,页面布局. 学习内容:html.div+css.js. 学习目标:div+css设计. 阶段二:php核心知识和数据库交互. 学习内容:php核心知 ...

  9. std::bad_alloc

    一个服务器程序,长时间运行报错了. ----------- terminate called after throwing an instance of 'std::bad_alloc' what() ...

  10. ld: 18 duplicate symbols for architecture i386 .linker command failed with exit code 1 (use -v to see invocation)_

    昨天被linker这个错误卡了一个小时!!!各种办法都试了 是导入第三方的问题 .. 网上说 要把所有的.m文件导入  但是我下载的微博SDK根本不关事..后来 大概知道是导入了多个相同的文件... ...