QUEUE BASED DATA STRUCTURE
It is a linear data structure represent a container of objects that are inserted and removed according to the first-in-firstout (FIFO) principle. That is, elements can be removed at any time, but only the element that has been in the queue the
longest can be removed at any time; that is random access of any specific item is not allowed. Queue elements may be
inserted at the back (called the REAR end) and removed from the front end (called FRONT end).
PRESENTATION OF QUEUE
Insertion
Deletio
n
Front
Rear
Algorithm 8.1: ENQUEUE-Let Q be a Queue consisting of N elements.
FRONT and REAR are pointers to the front and rear elements of a queue. This
algorithm inserts ITEM at the rear end of the queue.
Step 1: [Check for overflow]
If REAR = N Then
Display Overflow!
Exit
[EndIf]
Step 2: [Check for empty queue]
If FRONT = -1 Then
FRONT = 0 and REAR = 0 [Insert ITEM as first element of the queue]
Else
[Increment REAR pointer]
REAR = REAR + 1
[EndIf]
Step 3: Q[REAR] = ITEM
Step 4: Return
Algorithm 8.2: DEQUEUE-Let Q be a Queue consisting of N elements.
FRONT and REAR are pointers to the front and rear elements of a queue. This
algorithm deletes front element of the queue.
Step 1: [Check for Underflow]
If FRONT = -1 Then
Display Underflow!
Exit
[EndIf]
Step 2: [Delete front element]
Step 3:
[Empty queue?]
If FRONT = REAR Then
[Queue has only one element]
FRONT = -1 and REAR = -1
Else
[Increment FRONT pointer]
FRONT = FRONT + 1
[EndIf]
Step 4: Return