edit: delete this post. Figured out problem.
edit: delete this post. Figured out problem.
Last edited by mikeman; 02-15-2010 at 09:50 AM.
It is not quite so easy, methinks. The stack class that you have is implemented with a fixed size array. It is rather easy to implement a stack like this because you just need to add/remove elements from the end of the array by keeping track of the array size (and copying new elements, of course).Originally Posted by mikeman
But with a queue, this becomes problematic: you need to implement a ring buffer, or periodically shift elements (which tends to be slow), otherwise your queue's maximum size would be reduced as elements are removed from the queue, until you eventually have a queue that cannot store anything. You may find it easier to use a tailed singly linked list instead.
(That said, std::queue uses a std::deque by default, as does std::stack.)
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)