0% found this document useful (0 votes)
43 views

Queue Based Data Structure

A queue is a linear data structure that follows the FIFO (first-in, first-out) principle. Elements are inserted at the rear of the queue and removed from the front. The queue is represented using an array with pointers tracking the front and rear positions. The enqueue algorithm inserts elements at the rear by incrementing the rear pointer, while the dequeue algorithm removes the front element by incrementing the front pointer and checking for underflow or if the queue is empty.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Queue Based Data Structure

A queue is a linear data structure that follows the FIFO (first-in, first-out) principle. Elements are inserted at the rear of the queue and removed from the front. The queue is represented using an array with pointers tracking the front and rear positions. The enqueue algorithm inserts elements at the rear by incrementing the rear pointer, while the dequeue algorithm removes the front element by incrementing the front pointer and checking for underflow or if the queue is empty.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

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

You might also like