1 Replies - 81318 Views - Last Post: 22 September 2010 - 02:45 PM

#1 Guest_Guest*


Advantages/Disadvantages of Queues and Stacks

Posted 22 September 2010 - 12:47 PM

I'm new to computer programming and I'm learning about stacks and queues at the moment. What exactly are the advantages and disadvantages of both?
Is This A Good Question/Topic? 0

Replies To: Advantages/Disadvantages of Queues and Stacks

#2 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: Advantages/Disadvantages of Queues and Stacks

Posted 22 September 2010 - 02:45 PM

Stacks are last in first out so two major applications that Stacks accomplish are things like State and reversing. What I mean by state is a particular setting or structure that a program has at a point in time. Say you are writing a notepad application. A good use for a stack would be the undo/redo feature. Every time the user enters something, save the state (in this case, the text) on a stack and if you need to reverse something, just pop it off the top of the undo stack and push it onto the redo stack.

Stacks are also used for reversing things. If you push something, say a String onto a Stack one character at a time, and then construct a String from the members popped off the Stack, then the String is reversed.

Queues are good for things like storing the order in which something happened because you know that the first even happened first in the queue and the last happened last (unless it is a modified queue).

There's a few applications for you to ponder on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1