Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Queue and stacks

2,140 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Queue and stacks

  1. 1. Queue and stacks • What they are • How they work • How to make them • Typical problems
  2. 2. Sample exam question • What is a queue? • What is a stack? • How can one reverse the other?
  3. 3. Queue • First in • First Out FIFO
  4. 4. Stack • Last in • First out LIFO
  5. 5. The problem with queues • Queues work as you would expect – First in, First out - FIFO – Later items take their turn behind earlier ones. • Because of the ‘no shuffling’ rule, these turn out to be tricky to implement
  6. 6. Classic Array-Style Queue • Items are read off the front of the queue W H E R E sp T H E sp Front of Queue Rear of Queue Limit
  7. 7. Classic Array-Style Queue • And added to the rear W H E R E sp T H E sp S Front of Queue Rear of Queue Limit Item = W
  8. 8. Classic Array-Style Queue • Until we run out of space • Then we’re stuffed. W H E R E sp T H E sp S T R E Front of Queue Rear of Queue Limit Item = WHER Warning: Queue Full!
  9. 9. Brilliant Idea! • If you get to the end .. • Wrap round to the front • Until you hit the Rear pointer E E T R E sp T H E sp S T R E Front of QueueRear of Queue Limit Item = WHERE
  10. 10. Circular queue • It’s not really a circle! E E T R E sp T H E sp S T R E Front of Queue Rear of Queue EndStart

×