tags:

views:

546

answers:

3

Between vector and deque in C++ which one should I prefer in what situations?

+3  A: 

See this previous question for some clues:

http://stackoverflow.com/questions/102459/why-does-stdstack-use-stddeque-by-default

In particular, the link to Herb Sutter is useful.

Mark Ransom
A: 

Vector is useful when you are kinda sure about the length of the array. But if your are unsure of array length then deque is better.

Vectors and deques are similar but internally they differ in the way they grow.

The vector allocates memory contiguously when expanding memory where as deque does not allocate contiguous memory while expanding.

There was a code of mine that took half an hour to run but when i re factored it a bit and used deque it ran in 2 mins or so. I was using it for image processing

+5  A: 

GotW #54 answers this exactly.

luke