|
-
March 8th, 2011, 03:21 AM
#4
Re: vector vs. deque
The advantage of a deque is a relatively low worst case push_back. When you have a 1,000,000 item vector, and you need to push_back the 1,000,001st item, the reallocation is going to hurt... a lot.
They are just two different containers, they resemble each other, but at the end of the day, there are just too many considerations give you a clear cut answer.
Both vector and deque offer pretty good push_back performance. Vector seems to have a pretty good overall average case, but a bad worst case, whereas deque have an alright worst case.
Something else to consider is that deques never re-allocate. Objects are never copied around.
...
Oh yeah, push_front.
...
Personally, I usually stick with vectors, because I never need push_front, and enjoy the pointer/iterator compatibility, and the C-array style compatibility. And I'm more fluent in vector.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|