STL deque accessing by index is O(1)?

前端 未结 4 2042
眼角桃花
眼角桃花 2020-12-05 09:13

I\'ve read that accessing elements by position index can be done in constant time in a STL deque. As far as I know, elements in a deque may be stored in several non-contiguo

4条回答
  •  长情又很酷
    2020-12-05 10:05

    I found this deque implementation from Wikipedia:

    Storing contents in multiple smaller arrays, allocating additional arrays at the beginning or end as needed. Indexing is implemented by keeping a dynamic array containing pointers to each of the smaller arrays.

    I guess it answers my question.

提交回复
热议问题