Edit stack code to make queue

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....

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    54

    Edit stack code to make queue

    edit: delete this post. Figured out problem.
    Last edited by mikeman; 02-15-2010 at 08:50 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,914
    Quote Originally Posted by mikeman
    I'm attempting to alter a stack class and make it a queue. I don't think it should be that difficult, as I'm essentially changing it from first in last out (stack) to first in first out (queue).
    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).

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Pushing a Queue Onto Stack
    By programming1985 in forum C Programming
    Replies: 4
    Last Post: 10-22-2008, 07:44 PM
  3. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 01:56 AM
  4. queue help
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-29-2001, 08:38 AM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21