0% found this document useful (0 votes)
44 views24 pages

CC104 Chapter 4 Queues

Discrete Structure Lesson

Uploaded by

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

CC104 Chapter 4 Queues

Discrete Structure Lesson

Uploaded by

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

Search . . .

QUEUES
CHAPTER
4

MARIANNE C. SOLERO
Instructor
Search . . .

What is Queues?
A queue is a linear data structure where elements are stored in the
FIFO (First In First Out) principle where the first element inserted
would be the first element to be accessed.

A queue is an Abstract Data Type (ADT) similar to stack, the thing


that makes queue different from stack is that a queue is open at
both its ends.
Search . . .

Representation of Queues
A queue abstract data types can also be implemented using arrays,
linked lists, or pointers.
Queue uses two pointers − front and rear. The front pointer
accesses the data from the front end (helping in enqueueing) while
the rear pointer accesses data from the rear end (helping in
dequeuing).
Search . . .

For Example:
Search . . .

Basic Operations in Queue Data


Structure
Queues Data Structure Search . . .

Enqueue: Adds (or stores) an element to the end of the queue..


Dequeue: Removal of elements from the queue.
Peek or front: Acquires the data element available at the front node
of the queue without deleting it.
rear: This operation returns the element at the rear end without
removing it.
isFull: Validates if the queue is full.
isEmpty: Checks if the queue is empty.
Search . . .

4 Types of Queues Data


Structure
Search . . .

01. Simple Queue

Simple Queue simply follows FIFO Structure. We can only


insert the element at the back and remove the element
from the front of the queue.
Search . . .

02. Double-Ended Queue (Dequeue):

In a double-ended queue the insertion and deletion


operations, both can be performed from both ends. They are of
two types:

• Input Restricted Queue: This is a simple queue. In this


type of queue, the input can be taken from only one end
but deletion can be done from any of the ends.

• Output Restricted Queue: This is also a simple queue. In


this type of queue, the input can be taken from both
ends but deletion can be done from only one end.
Double ended Queue:
Input Restricted Queue

Output Restricted Queue


03. Circular Queue Search . . .

is a linear data structure in which the operations are


performed based on FIFO (First In First Out) principle and the last
position is connected back to the first position to make a circle. It
is also called ‘Ring Buffer’.
Representation of Circular Queue
04. Priority Queue Search . . .

is a special queue where the elements are accessed based on the


priority assigned to them. They are of two types:

Ascending Priority Queue: the elements are arranged in increasing


order of their priority values. Element with smallest priority value is
popped first.

Descending Priority Queue: the elements are arranged in decreasing


order of their priority values. Element with largest priority is popped
first.
04. Priority Queue Search . . .
Search . . .

Array Implementation of Queues


Array implementation Of Queue: Search . . .

Steps for enqueue:


1. Check the queue is full or not
2. If full, print overflow and exit
3. If queue is not full, increment tail and add the element

Steps for dequeue:


1. Check queue is empty or not
2. if empty, print underflow and exit
3. if not empty, print element at the head and increment head
Search . . .
Search . . .

Linked List Implementation of


Queues
Linked List Implementation Of Queue: Search . . .

Steps for enqueue(data)


1. Build a new node with given data.
2. Check if the queue is empty or not.
3. If queue is empty then assign new node to front and rear.
4. Else make next of rear as new node and rear as new
node.
Steps for dequeue()
1. Check if queue is empty or not.
2. If queue is empty then dequeue is not possible.
3. Else store front in temp
4. And make next of front as front.
Linked List Implementation Of Queue: Search . . .

Steps for print()


1. Check if there is some data in the queue or not.
2. If the queue is empty print “No data in the queue.”
3. Else define a node pointer and initialize it with front.
4. Print data of node pointer until the next of node pointer
becomes NULL.
Linked List Implementation Of Queue: Search . . .
REFERENCES: Search . . .

• https://www.geeksforgeeks.org/introduction-to-queue-data-structure
-and-algorithm-tutorials/
• https://www.tutorialspoint.com/data_structures_algorithms/dsa_queu
e.htm
• https://www.geeksforgeeks.org/different-types-of-queues-and-its-app
lications/
Search . . .

THANK YOU
END SLIDE

MARIANNE C.
SOLERO
Instructor

You might also like