edit: delete this post. Figured out problem.
This is a discussion on Edit stack code to make queue within the C++ Programming forums, part of the General Programming Boards category; edit: delete this post. Figured out problem....
edit: delete this post. Figured out problem.
Last edited by mikeman; 02-15-2010 at 08: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.)
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way