SlideShare a Scribd company logo
STACK & QUEUE
Dr. R. Khanchana
Assistant Professor
Department of Computer Science
Sri Ramakrishna College of Arts and Science for Women
STACK
E –Book – Chapter 3 :
http://icodeguru.com/vc/10book/books/book1/chap03.htm
Stack Tutorial
https://www.studytonight.com/data-structures/stack-data-structure
STACK - EXAMPLES
CHAPTER 3 : http://icodeguru.com/vc/10book/books/book1/chap03.htm
Stacks
•The most common data
objects in the computer
algorithms are Stacks and
Queues.
•Stacks are dynamic data
structures that follow
the Last In First Out
(LIFO) principle
•An Ordered List in which
all the insertions and
deletions take place at the
one end called Top.
Bottom
Stacks
Operations: The operation that can be performed on the stack are:
CREATE(S) – This Procedure creates S an empty stack.
ADD(i,S) – This procedure inserts an element i into the
stack S and returns the new stack.
DELETE(i,S) – This procedure removes the top most element
from the stack S and returns the new stack.
TOP(S) – This procedure returns the top most element
of the stack S.
ISEMT(S) – This procedure returns true, if S is an empty
STACK Implementations
• CREATE ( ) :: = declare STACK(1:n); top 0
• ISEMTS(STACK) :: = if top = 0 then true
• else false
• TOP(STACK) :: = if top = 0 then error
else STACK(top)
Procedure - Stack
Procedures- Push
procedure ADD (item, STACK, n, top)
//insert item into the STACK of maximum size n; top is the number of
elements currently in STACK//
if top n then call STACK_FULL
Top top + 1
STACK (top) item
end ADD
Procedures - Pop
procedure DELETE (item, STACK, top)
//removes the top element of STACK and stores
it in item
unless STACK is empty//
if top 0 then call STACK_EMPTY
item STACK (top)
Top top - 1
end DELETE
STACK OPERATIONS
QUIZ
• https://quizizz.com/admin/quiz/5f08716a58b
4e9001cbeca8a
Feedback
• https://docs.google.com/forms/d/1kSoCAmQ
dfuf2kIWFEkl8xZQKMAluyXS6XyYGjXDwXcw/e
dit
QUEUE
E –Book – Chapter 3 :
http://icodeguru.com/vc/10book/books/book1/chap03.htm
Queue – Tutorial
https://www.tutorialride.com/data-structures/queue-in-data-
structure.htm
Queue - Examples
CHAPTER 3 : http://icodeguru.com/vc/10book/books/book1/chap03.htm
Difference Between Stack & Queue
Queue -Understanding
Queue – Insertion & Deletion
Queue Operations
• CREATEQ(Q) which creates Q as an empty queue;
• ADDQ(i,Q) which adds the element i to the rear
of a queue and returns the new queue;
• DELETEQ(Q) which removes the front element
from the queue Q and returns the resulting
queue;
• FRONT(Q) which returns the front element of Q;
• ISEMTQ(Q) which returns true if Q is empty else
false.
Queue Implementations
CREATEQ(Q) :: = declare Q(l:n); front rear 0
ISEMTQ(Q) :: = if front = rear then true
else false
FRONT(Q) :: = if ISEMTQ(Q) then error
else Q(front + 1)
Queue -Procedure
Queue –ADD Procedure
Queue – Delete Procedure
QUIZ
• https://quizizz.com/admin/quiz/5f0c472c48e3
69001bb0d69a/data-structure-queue
Feedback
• https://docs.google.com/forms/d/1A8Dgtkn4
A1g8-
QiQA1W6hvyRNhR7OMl_VxA9TyYNMog/edit
Circular Queue
Linear Queue Vs Circular Queue
Enqueue -6 Elements
Dequeue – 3 Elements
Enqueue – One more element
Circular Queue
• Circular Queue is a bounded queue which implements arrays.
• It is better than a normal queue because it will effectively
utilize the memory space.
• If we have a normal queue and have deleted some elements
an empty space is created.
• Even if the queue has empty space we cannot insert any new
element because the inserting has to be done from one side
only(Rear) and deletions has to be done from another
side(front).
• In case of Circular Queue the Front and Rear are adjacent to
each other. Hence we can insert a new element in the empty
space (i.e the space from where the element is deleted).
Queue Implementations
• https://i1.faceprep.in/Companies-1/circular-
queue-implementation.gif
Circular Queue – ADD Procedure
Procedure ADD(i,Q,n,rear)
//insert the element i into the Queue
rear=(rear+1) mod n;
If front = rear then call Queue_Full
Q(rear)=item;
end ADD
Circular Queue –Addition(Enqueue)
Circular Queue – Delete Procedure
Procedure DELETE(i,Q,front,rear)
//insert the element i into the Queue
If front=rear then call Queue_Empty
front = (front +1) mod n;
i=Q(front);
end DELETE
Enqueue & Dequeue
Multiple Stack & Queue
Multiple Stacks
Multiple Queues
Multiple Stack
• Boundary condition
– B(i) = T(i) iff the i'th stack is empty
Multiple Stack – Insertion and Deletion
Quiz
• https://quizizz.com/admin/quiz/5f0e8c1b367f
66001cbc9e7e
Feedback
• https://docs.google.com/forms/d/1Twhq95BD
Pmsn4UPqGdqG1z4BQaLbgPKftmyp9CsYLJU/e
dit

More Related Content

PPTX
Unit I-Data Structures_Intoduction.pptx
PPT
Unit 3 Tree chapter 5
PPT
Unit 3 graph chapter6
PPTX
Unit 2 linked list
PPTX
Unit 4 plsql
PPTX
Professor Profile Presentation example .
PPTX
Trees (data structure)
PPT
Computer maintenance
Unit I-Data Structures_Intoduction.pptx
Unit 3 Tree chapter 5
Unit 3 graph chapter6
Unit 2 linked list
Unit 4 plsql
Professor Profile Presentation example .
Trees (data structure)
Computer maintenance

What's hot (20)

PPT
Unit 4 external sorting
PPTX
Unit 5 internal sorting & files
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
Unit I - Evaluation of expression
PPTX
Polynomial reppresentation using Linkedlist-Application of LL.pptx
PPTX
Stack project
PPTX
Linked List
PPTX
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
PPTX
Queues in C++
PPTX
Queue - Data Structure - Notes
PPTX
queue & its applications
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
PPTX
trees in data structure
PPTX
Binary Tree in Data Structure
PPT
Linked List
PPTX
Graph representation
PPTX
Stacks and Queue - Data Structures
PPTX
PPT
Unit 4 external sorting
Unit 5 internal sorting & files
BINARY TREE REPRESENTATION.ppt
Unit I - Evaluation of expression
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Stack project
Linked List
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Queues in C++
Queue - Data Structure - Notes
queue & its applications
Trees, Binary Search Tree, AVL Tree in Data Structures
trees in data structure
Binary Tree in Data Structure
Linked List
Graph representation
Stacks and Queue - Data Structures
Ad

Similar to Unit I-Data structures stack & Queue (20)

PPTX
Stack and queue
PPTX
CD3291 2.5 stack.pptx
PPT
The Stack in data structures .ppt
PPTX
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
PPTX
Data structure , stack , queue
PPTX
Stack.pptx
PPT
Difference between stack and queue
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PPTX
CHAPTER 4 Learning QUEUE data structure.pptx
PPT
stack and queue array implementation in java.
PPT
stack and queue array implementation, java.
PPTX
DS ppt1.pptx.c programing. Engineering. Data structure
PPTX
Stack and Queue.pptx university exam preparation
PDF
Queue
PPT
Data Structures
PDF
Chapter 5 Stack and Queue.pdf
 
PPTX
Stack and Queue.pptx
 
PPTX
DSEC1.pptx stack exchange communities that I am not đźš­ hi nahi
Stack and queue
CD3291 2.5 stack.pptx
The Stack in data structures .ppt
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
Data structure , stack , queue
Stack.pptx
Difference between stack and queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
CHAPTER 4 Learning QUEUE data structure.pptx
stack and queue array implementation in java.
stack and queue array implementation, java.
DS ppt1.pptx.c programing. Engineering. Data structure
Stack and Queue.pptx university exam preparation
Queue
Data Structures
Chapter 5 Stack and Queue.pdf
 
Stack and Queue.pptx
 
DSEC1.pptx stack exchange communities that I am not đźš­ hi nahi
Ad

Recently uploaded (20)

PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Classroom Observation Tools for Teachers
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
GDM (1) (1).pptx small presentation for students
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Classroom Observation Tools for Teachers
102 student loan defaulters named and shamed – Is someone you know on the list?
human mycosis Human fungal infections are called human mycosis..pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Sports Quiz easy sports quiz sports quiz
Module 4: Burden of Disease Tutorial Slides S2 2025
O5-L3 Freight Transport Ops (International) V1.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Final Presentation General Medicine 03-08-2024.pptx
GDM (1) (1).pptx small presentation for students

Unit I-Data structures stack & Queue