On 12/02/2010 04:54 PM, Vincent van Ravesteijn wrote:
I read somewhere that stacks are best implemented as deques. Don't ask me
why now,
but I think they are slightly cheaper. (I'm sure Andre would have a view
about this.)
Some googling gives me:
The C++ Standard, in section 23.1.1, offers some advice on which
containers to prefer. It says:
"vector is the type of sequence that should be used by default...
deque is the data structure of choice when most insertions and
deletions take place at the beginning or at the end of the sequence."
That's our case: It's being used as a stack, so insertions and deletions
always take place at the end.
I guess the advantage to a deque here is that it doesn't allow you to do
things you shouldn't be doing,
like random access.
Richard