Блог пользователя VoolDD5

Автор VoolDD5, 10 лет назад, По-английски

Hi!
can you please tell me why people use vector while deque do the same with much more features :(

  • Проголосовать: нравится
  • +12
  • Проголосовать: не нравится

»
10 лет назад, # |
  Проголосовать: нравится -19 Проголосовать: не нравится

Really? I didn't know you can find/change the value of an arbitrary element of a deque in O(1)...

»
10 лет назад, # |
  Проголосовать: нравится +30 Проголосовать: не нравится

Both vectors and deques provide a very similar interface and can be used for similar purposes, but internally both work in quite different ways: While vectors use a single array that needs to be occasionally reallocated for growth, the elements of a deque can be scattered in different chunks of storage

from cplusplus.com

Therefore the indexing operator[]() could take more time because you need to determine the certain chunk of memory at first and then the position of an element in this chunk.

And second point — it might be very confusing for the reader of the code to see a deque where he expected one of more standard array types.