What data structure, exactly, are deques in C++?

后端 未结 7 996
我寻月下人不归
我寻月下人不归 2020-12-04 19:44

Is there a specific data structure that a deque in the C++ STL is supposed to implement, or is a deque just this vague notion of an array growable from both the front and th

7条回答
  •  离开以前
    2020-12-04 19:53

    It's implementation specific. All a deque requires is constant time insertion/deletion at the start/end, and at most linear elsewhere. Elements are not required to be contiguous.

    Most implementations use what can be described as an unrolled list. Fixed-sized arrays get allocated on the heap and pointers to these arrays are stored in a dynamically sized array belonging to the deque.

提交回复
热议问题