Nov01


Data Structure: Queue image

It is a linear data structure in which all insertions are made from one end, called rear of the queue and all deletions are made from the other end, called the front of the queue.

It follows FIFO (First-in First-out).

To remove a newly inserted item from the queue, all the items inserted before the newly inserted item must be removed from the queue.


|0 |0

Memory Representation

A queue may be represented in memory in two ways:

  1. Array representation
  2. Linked (or pointer) representation

Array representation

In this representation, we use an array, say q[n] and two variables front and rear which contain the location of the front and rear element of the queue respectively.

A queue represented by an array q[n] containing four elements
A queue represented by an array q[n]containing four items

 

 

  • Queue empty (underflow) condition
    When queue is empty, the values of front and rear are set equal to -1 and the condition front = rear = -1 is true.
Diagrammatic representation of an empty queue

 

  • Queue full (overflow) condition
    When the queue is full then the value of rear is n-1 and the condition rear=n-1 is true.
Diagrammatic representation of a full queue

Ads By Google - Turn it Off

Leave a Comment


gfhdg