VoolDD5's blog

By VoolDD5, 12 years ago, In English

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

  • Vote: I like it
  • +12
  • Vote: I do not like it

| Write comment?
»
12 years ago, hide # |
 
Vote: I like it -19 Vote: I do not like it

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

»
12 years ago, hide # |
 
Vote: I like it +30 Vote: I do not like it

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.