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.

转载于:https://www.cnblogs.com/gaoxianzhi/p/5551859.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值