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