zoukankan      html  css  js  c++  java
  • vector list array deque

    因此在实际使用时,如何选择这三个容器中哪一个,应根据你的需要而定,一般应遵循下面
    的原则:
      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.

  • 相关阅读:
    mysql 设置无密码登陆
    phpstudy mysql 升级5.7.18
    php 统计二维数组中某个相等值的总个数,并且组合成一个新的数组 转发
    centos 安装 composer
    PHP不定维数组去除空值
    jQuery中$.ajax()详解(转)
    JSON详解(转发自博客园)
    详解CMS垃圾回收机制
    内存管理
    什么是同源策略
  • 原文地址:https://www.cnblogs.com/gaoxianzhi/p/5551859.html
Copyright © 2011-2022 走看看