Queue and stacks

952 views
771 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
952
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

×