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
2008-09-26 14:22:26
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