What's the difference between deque and list STL containers?

前端 未结 8 1595
滥情空心
滥情空心 2020-12-07 10:08

What is the difference between the two? I mean the methods are all the same. So, for a user, they work identically.

Is that correct??

8条回答
  •  星月不相逢
    2020-12-07 11:04

    Among eminent differences between deque and list

    • For deque :

      Items stored side by side;

      Optimized for adding datas from two sides (front, back);

      Elements indexed by numbers (integers).

      Can be browsed by iterators and even by element's index.

      Time access to data is faster.

    • For list

      Items stored "randomly" in the memory;

      Can be browsed only by iterators;

      Optimized for insertion and removal in the middle.

      Time access to data is slower, slow to iterate, due to its very poor spatial locality.

      Handles very well large elements

    You can check also the following Link, which compares the performance between the two STL containers (with std::vector)

    Hope i shared some useful informations.

提交回复
热议问题