0% found this document useful (0 votes)
25 views17 pages

PPT Lecture 3.3.1 Queue

The document outlines a course on Elementary Data Structures using C++, focusing on queues and their operations. It details course objectives, outcomes, and algorithms for insertion and deletion in both regular and circular queues. Additionally, it highlights applications of queues in various fields and provides references for further reading.
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)
25 views17 pages

PPT Lecture 3.3.1 Queue

The document outlines a course on Elementary Data Structures using C++, focusing on queues and their operations. It details course objectives, outcomes, and algorithms for insertion and deletion in both regular and circular queues. Additionally, it highlights applications of queues in various fields and provides references for further reading.
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/ 17

UNIVERSITY INSTITUTE OF ENGINEERING

DEPARTMENT- ACADEMIC UNITS


Bachelor of Engineering (Computer Science &
Engineering)
Subject Name : Elementary Data Structures using C++
Subject Code: 23CSH-103

QUEUE DISCOVER . LEARN . EMPOWER


Elementary Data
Structure Using C++

Course Objectives

• To enable the students to understand


various stages and constructs of C++
programming language.
• To improve their ability to analyze and
address variety of problems in C++.
• To understand the concept of data
structures and various operations on
them.
• To understand the properties of
various data structures and able to
identify the strengths and weaknesses
of different data structures.
• To analyze and compare the efficiency
of algorithms and learn to design
2
efficient algorithms for solving
Course Outcomes
CO Course Outcome
Number

CO1 Understand the concepts of object-oriented programming including


programming process and compilation process.
CO2 Apply different techniques to decompose a problem and
programmed a solution with various concepts of object-oriented
programming language.
CO3 Analyse and explain the behaviour of linear data structure
operations using the programming addressed in the course.
CO4 Implement and evaluate the programs using the syntax and
semantics of object-oriented programming.
CO5 Design the solution of real-world problems in order to determine
that the program performs as expected.

3
Scheme of Evaluation

4
• A Queue is "an abstract data type in which
elements are added to the rear and removed
QUEUE from the front; a 'first in, first out' (FIFO)
structure."
A queue is a data structure
that stores data in such a way
that the last piece of data
stored, is the last one
retrieved
also called First-In, First-
Out (FIFO)
Only access to the stack is the
first and last element http://www.cs.uregina.ca/Links/class-info/210/Queue/

consider people standing in


line , they get service in the
order that they arrive
5
Queues
• Enque
• operation to place a new item at the tail of the queue
• Dequeue
• operation to remove the next item from the head of the queue
Queue
start end

X A M

enqueue(F)

start end start end

X A M F A M F
item = dequeue()
item = X
ALGORITHM FOR INSERTION
1. If REAR=MAX then: write: Overflow & Exit
2. Read ITEM
If FRONT=0 then:
a) FRONT=FRONT+1
b) REAR=REAR+1
c) Q[REAR]=ITEM
else
REAR=REAR+1
Q[REAR]=ITEM
3. Exit

8
ALGORITHM FOR DELETION
• If FRONT=0 then: write: “UNDERFLOW and Exit”
• If FRONT=REAR, then:
Q[FRONT]=NULL
FRONT=0
REAR=0
else
Q[FRONT]=NULL
FRONT=FRONT+1
• Exit

9
Circular Queue
• Circular queue 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’.

10
• In a normal Queue, we can insert elements until queue becomes full.
But once queue becomes full, we can not insert the next element
even if there is a space in front of queue.

11
Operations on Circular Queue:
• Front: Get the front item from queue.
• Rear: Get the last item from queue.
• enQueue(value) This function is used to insert an element into the
circular queue. In a circular queue, the new element is always
inserted at Rear position.
• Steps:Check whether queue is Full – Check ((rear == SIZE-1 && front == 0) ||
(rear == front-1)).
• If it is full then display Queue is full. If queue is not full then, check if (rear ==
SIZE – 1 && front != 0) if it is true then set rear=0 and insert element.
• deQueue() This function is used to delete an element from the
circular queue. In a circular queue, the element is always deleted
from front position.

12
Steps:
Step 1:Check whether queue is Empty means check (front==-1).
Step 2:If it is empty then display Queue is empty. If queue is not empty then
step 3
Step 3:Check if (front==rear) if it is true then set front=rear= -1 else check if
(front==size-1), if it is true then set front=0 and return the element.
Time Complexity: Time complexity of enQueue(), deQueue() operation is
O(1) as there is no loop in any of the operation.
Applications:
• Memory Management: The unused memory locations in the case of
ordinary queues can be utilized in circular queues.
• Traffic system: In computer controlled traffic system, circular queues are
used to switch on the traffic lights one by one repeatedly as per the time
set.
• CPU Scheduling: Operating systems often maintain a queue of processes
that are ready to execute or that are waiting for a particular event to occur.13
FAQ

1. Give any 2 applications of stack


2. Give any 2 applications of queue
3. Advantages of Stack over Queues

14
Applications of Queue
• Print lines of a document
• Simulation
• Printer sharing between computers

15
REFERENCES

• https://www.cs.cmu.edu/~adamchik/15-121/lectures/Stacks%20and%20Queues/Stacks%20and%2
0Queues.html
• Data Structures with C/ schaum outline series/ volume 2
• https://www.geeksforgeeks.org/stack-data-structure-introduction-program/
• https://www.geeksforgeeks.org/queue-set-1introduction-and-array-implementation/
• http://www.yashcode.com/2017/11/prefix-to-postfix-conversion-using-stack.html
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill.
• Gilberg/Forouzan,” Data Structure with C ,Cengage Learning.
• Augenstein,Moshe J , Tanenbaum, Aaron M, “Data Structures using C and C++”, Prentice Hall of
India.
• Goodrich, Michael T., Tamassia, Roberto, and Mount, David M., “Data Structures and Algorithms in
C++”, Wiley Student Edition.
• Aho, Alfred V., Ullman, Jeffrey D., Hopcroft ,John E. “Data Structures and Algorithms”, Addison
Wesley
16
THANK YOU

You might also like