0% found this document useful (0 votes)
8 views16 pages

Queue Lecture

Uploaded by

manndober972
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views16 pages

Queue Lecture

Uploaded by

manndober972
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

DATA STRUCTURE

Course Code : ENCS205

Linear Data Structure : Queue

Dr Swati
Associate Professor
Faculty School of Engineering & Technology (SOET)
K. R. Mangalam University
LINEAR DATA STRUCTURE

QUEUE

https://www.scaler.com/topics/data-structures
/queue-in-data-structure
QUEUE
 A Queue is a linear data structure that contains elements in an
ordered sequence.
 It comprises of two ends FRONT and REAR

Fig 4 :Linear Data structure Queue

https://www.javatpoint.com/data-structure-queue
Real World Applications of QUEUE

First In First
Out

https://data-flair.training/blogs/stacks-and-que
ues-in-c
/
Real World Applications of QUEUE
In Escalators, vehicles at toll center- Queue (Data Structure)

https://data-flair.training/blogs/stacks-and-que
ues-in-c
/
Array Representation of Queue
 Queue can easily be represented using linear Array.

Fig 3 : Array representation of Queue

https://www.shiksha.com/online-courses/articles/difference-between-array-an
d-linked-list
/.
Operations on Queue

Enqueue() : Inserting a new element in the Queue

Dequeue() : Deleting an element from the Queue


What is Happening in the Picture ??
OVERFLOW CONDITION IN QUEUE
 An overflow condition in a queue occurs when an attempt is
made to add an element to a queue that is already at its
maximum capacity.

IF REAR = MAX-1 (OVERFLOW CONDITION)


MAX is the maximum number of elements a
Queue can hold
Algorithm for Adding an Element in
Queue
Step
Step1:1:[Check
[CheckQueue
Queueisisalready
alreadyfilled
filled?]
?]
IFIFREAR
REAR==MAX MAX––11Write
WriteOVERFLOW
OVERFLOWGo Gototostep
step44
[END
[ENDOF OFIF]IF]
Step
Step2:2:IfIfFront
Front==-1
==-1and
andRear==-1
Rear==-1// //Queue
Queueisisinitially
initiallyempty
empty
Set
SetFront
Front==00and
andRear
Rear==00
Else
Else
Set
SetRear=Rear
Rear=Rear++11
[END
[ENDOF OFIF]IF]
Step
Step3:3:Set
SetQueue
Queue[Rear]=
[Rear]=ITEM
ITEM
Step
Step44::Exit
Exit
EXAMPLE OF ENQUEUE OPERATION
STEP 1 : Initially the Queue is Empty

Front=-1 and Rear =-1

STEP 2 : Insert an element 10

Front= 0 and Rear = 0

STEP 3 : Insert an element 20

Front= 0 and Rear = 1

STEP 4 : Insert an element 30

Front= 0 and Rear = 2


UNDERFLOW CONDITION IN QUEUE
 An underflow refers to a situation where an attempt is made to
dequeue (remove) an element from an empty queue.

IF front = = -1 ( CONDITION)
Algorithm for Deleting an Element
from Queue
Step
Step 1:
1: IF
IF FRONT
FRONT == -1
-1 or
or FRONT
FRONT >> REAR
REAR
Write
Write UNDERFLOW
UNDERFLOW
ELSE
ELSE
SET
SET VAL
VAL == QUEUE[FRONT]
QUEUE[FRONT]
SET
SET FRONT
FRONT == FRONT
FRONT ++ 11
[END
[END OF
OF IF]
IF]
Step
Step 2:
2: EXIT
EXIT
EXAMPLE OF DEQUEUE OPERATION
STEP 1 : Initially the Queue comprises of three elements

Front= 0 and Rear = 2

STEP 2 : Delete an element 10

Front= 1 and Rear = 2

STEP 3 : Delete an element 20

Front= 2 and Rear = 2


Practise Question
 An online ticketing system manages ticket requests in the order they are
received. Each request has a unique request ID. New requests are added to the
end of the queue, and requests are processed from the front of the queue.
Implement a fixed-size linear queue to handle these ticket requests.
Questions:
 Basic Operations:
Insertion (enqueue): Write a function to add a new ticket request to the queue.
Deletion (dequeue): Write a function to remove the next ticket request from the
queue when it is processed.
 Advanced Operations:
Size: Write a function to return the number of ticket requests currently in the
queue.
IsFull: Write a function to check if the queue is full (assuming a fixed-size array
implementation).
THANK YOU

You might also like