Why would I prefer using vector to deque

前端 未结 10 1737
陌清茗
陌清茗 2020-11-29 17:10

Since

  1. they are both contiguous memory containers;
  2. feature wise, deque has almost everything vector has but more, since it is more efficient to insert
10条回答
  •  星月不相逢
    2020-11-29 17:54

    Note that vector memory is re-allocated as the array grows. If you have pointers to vector elements, they will become invalid.

    Also, if you erase an element, iterators become invalid (but not "for(auto...)").

    Edit: changed 'deque' to 'vector'

提交回复
热议问题