Queues

Subtitle


Contents

What are queues

A queue is a first in first out data structure. Any new items can only be added the end of the queue. Items may only be removed from the front of the queue.

Usages

  • Printers
  • CPU interrupts
  • Keys pressed on a keyboard.

Operations on a Queue

Operations on a Queue

Subtitle


Queues have operations on them that allow for items to be removed and added from the queue.

Basic operations

Here is a basic queue with its pointers

ABCD
front=0rear=3

Adding (enqueue)

ABCDE
front=0rear=4

Removing (dequeue)

Note

The elements do not move.

BCDE
front=1rear=4

Other operations

  • isEmpty - Checks if the array is empty or not
  • isFull - Checks if the array is full or not
Link to original