SlideShare a Scribd company logo
9
Most read
10
Most read
11
Most read
DATA STRUCTURE
STACKS AND QUEUES
Prepared by : SELVIN JOSY BAI.S
STACK
 It is a linear data structure in which an elements
may be inserted or deleted only at one end called the
top of the stack.
 This data structure implemented in LIFO (Last In
First Out) manner
 LIFO means element last inserted would be the first
one to be deleted.
 The Stack is also a dynamic data structure as it
can grow or shrink.
 Real life example :
 A stack OF DISCS IN HOLDER
 A stack of TOKENS IN HOLDER
 Two basic operations of stack
 PUSHING : An Insertion in a stack is called
PUSHING.
 POPPING : A Deletion from a stack is called
POPPING.
PUSHING ALGORITHM
1. Read ITEM
2. If TOP = N then Print “OVERFLOW”
and Stop
3. Else set TOP = TOP + 1
//Creating a space for a new element
4. Set STACK [ TOP ] = ITEM
//Inserting the new ITEM
5. Stop
1 2 3 4 5
TOP
N 5
NULL
POPPING ALGORITHM
1. If TOP = NULL then
Print “UNDERFLOW” and return
2. Else set ITEM =STACK [ TOP ]
3. Set TOP = TOP - 1
4. Stop
1 2 3 4 5
TOP
APPLICATIONS OF STACK
 TO REVERSING A STRING
 TO EVALUATE NOTATIONAL
EXPRESSION(INFIX, PREFIX, & POSTFIX)
 TO CONVERT FROM ONE EXPRESSION TO
ANOTHER.
QUEUE
 It is a linear data structure in which an element may
be inserted only at one end, called the REAR end and
deletions can be take place at the other end, called the
FRONT end.
 This data structure implemented in FIFO (First In
First Out) manner
 FIFO means element first inserted would be the first
one to be deleted.
 The Queue is also a dynamic data structure as it can
grow or shrink.
 However, if additions and deletions are made at both
ends of a queue, then such a queue is called Double
Ended Queue or simply DEQUE.
The following operations can be performed
on Queues
1. Addition of an element at the REAR end of the
queue
2. Deletion of an element from the FRONT end of
the queue
Real life example :
• People waiting at a railway station counter for
taking tickets
Algorithm for INSERTION
1. If FRONT = 1 and REAR = N or
If FRONT = REAR + 1 then
Print “OVERFLOW” ; stop
2. if FRONT = NULL then
set FRONT = 1 and REAR = 1
3. Else if REAR = N then
set REAR = 1
4. Else set REAR = REAR + 1
5. Endif
6. Set QUEUE [ REAR ] = ITEM
7. Stop
Algorithm for DELETION
1. If FRONT = NULL then
Print “UNDERFLOW” ; stop
2. set ITEM = QUEUE [FRONT]
3. If FRONT = REAR then
set FRONT = NULL and REAR = NULL
4. Else if FRONT = N then set FRONT = 1
5. Else set FRONT = FRONT + 1
6. Stop
APPLICATIONS OF QUEUE
 IT OCCURS IN THE JOB SCHEDULING
 THE COMPUTER OS USE THIS CONCEPT
IN SCHEDULING THE MEMORY,
PROCESSOR AND THE FILES.
 USED FOR SCHEDULING JOBS AND
SERVICES.
EXERCISE - 1
 In CD pack, the CDs are placed one over the
other through a central axis. Assume that there
are 25 CDs in the pack.
a. Name the data structure that resembles with the
CD pack.
b. Considering the CD pack as an array in C++, how
will you name the position of the last CD and what
will be its value?
c. Write an algorithm to remove a CD from the pack
and name the operation performed.
EXERCISE - 2
 While waiting for a ticket at the railway station
ticket counter, you are following the principle
as that of a data structure
a. Name the data structure and the principle
b. Write a C++ function to add a new element in this
data structure.
c. Name the situation where there is no space for
adding new element
Some more Questions
1. What is overflow and underflow?
2. Explain the terms PUSH and POP?
3. What are the applications of stacks and
queues?
4. Name the data structure that resembles a
person placing plates in a vessel. Write
an algorithm for inserting a plate.

More Related Content

What's hot (20)

PPT
stack presentation
Shivalik college of engineering
 
PDF
Revised Data Structure- STACK in Python XII CS.pdf
MohammadImran709594
 
PPTX
linked list in data structure
shameen khan
 
PPTX
Introduction to stack
vaibhav2910
 
PPTX
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
PDF
Applications of stack
eShikshak
 
PDF
Queue as data_structure
eShikshak
 
PPTX
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
PPSX
Stack
Seema Sharma
 
PPTX
Queue in Data Structure
Janki Shah
 
PPT
Stack
srihariyenduri
 
PPTX
stack & queue
manju rani
 
PPTX
Two dimensional arrays
Neeru Mittal
 
PPTX
queue & its applications
somendra kumar
 
PPTX
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
PPTX
My lectures circular queue
Senthil Kumar
 
PPTX
Stack and Queue
Apurbo Datta
 
PPT
Queue Data Structure
Zidny Nafan
 
PPTX
Heap sort
Ayesha Tahir
 
Revised Data Structure- STACK in Python XII CS.pdf
MohammadImran709594
 
linked list in data structure
shameen khan
 
Introduction to stack
vaibhav2910
 
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
Applications of stack
eShikshak
 
Queue as data_structure
eShikshak
 
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Queue in Data Structure
Janki Shah
 
stack & queue
manju rani
 
Two dimensional arrays
Neeru Mittal
 
queue & its applications
somendra kumar
 
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
My lectures circular queue
Senthil Kumar
 
Stack and Queue
Apurbo Datta
 
Queue Data Structure
Zidny Nafan
 
Heap sort
Ayesha Tahir
 

Viewers also liked (9)

PDF
Queues
Hareem Aslam
 
PPT
Queue and stacks
grahamwell
 
PPTX
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
Shail Nakum
 
PPT
Queue
Nabeel Ahsen
 
PPTX
Ppt presentation of queues
Buxoo Abdullah
 
PPTX
Presentation on half and full wave ractifier.ppt
Kawsar Ahmed
 
PPT
Notes DATA STRUCTURE - queue
Farhanum Aziera
 
PPT
DATA STRUCTURES
bca2010
 
Queues
Hareem Aslam
 
Queue and stacks
grahamwell
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
Shail Nakum
 
Ppt presentation of queues
Buxoo Abdullah
 
Presentation on half and full wave ractifier.ppt
Kawsar Ahmed
 
Notes DATA STRUCTURE - queue
Farhanum Aziera
 
DATA STRUCTURES
bca2010
 
Ad

Similar to Data structure stack&queue basics (20)

PPT
Difference between stack and queue
Pulkitmodi1998
 
PPT
Rana Junaid Rasheed
Rana junaid Rasheed
 
PPT
Stacks queues-1220971554378778-9
Getachew Ganfur
 
PPT
Stacks & Queues
tech4us
 
PPT
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
PPT
The Stack in data structures .ppt
donemoremaregere376
 
PPTX
Stacks in c++
Vineeta Garg
 
PPTX
Stack.pptx
SherinRappai
 
PDF
04 stacks
Rajan Gautam
 
PPT
Data Structures by Maneesh Boddu
maneesh boddu
 
PPTX
Introduction to information about Data Structure.pptx
tarrebulehora
 
PDF
Stacks,queues,linked-list
pinakspatel
 
PPT
Linear Datsructure_stacks_Data Structure_PPT.ppt
rajinooka
 
PPT
stack data structure and its applications , advantages, disadvantages etc
rajinooka
 
PPT
stack data structure , applications, advantages
rajinooka
 
PDF
stacks and queues
DurgaDeviCbit
 
DOCX
CDS artificial intelligence and Machine.docx
msurfudeen6681
 
PPTX
Stack and its operations, Queue and its operations
poongothai11
 
PPTX
Stacks Data structure.pptx
line24arts
 
PPTX
Data Structures Stack and Queue Data Structures
poongothai11
 
Difference between stack and queue
Pulkitmodi1998
 
Rana Junaid Rasheed
Rana junaid Rasheed
 
Stacks queues-1220971554378778-9
Getachew Ganfur
 
Stacks & Queues
tech4us
 
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
The Stack in data structures .ppt
donemoremaregere376
 
Stacks in c++
Vineeta Garg
 
Stack.pptx
SherinRappai
 
04 stacks
Rajan Gautam
 
Data Structures by Maneesh Boddu
maneesh boddu
 
Introduction to information about Data Structure.pptx
tarrebulehora
 
Stacks,queues,linked-list
pinakspatel
 
Linear Datsructure_stacks_Data Structure_PPT.ppt
rajinooka
 
stack data structure and its applications , advantages, disadvantages etc
rajinooka
 
stack data structure , applications, advantages
rajinooka
 
stacks and queues
DurgaDeviCbit
 
CDS artificial intelligence and Machine.docx
msurfudeen6681
 
Stack and its operations, Queue and its operations
poongothai11
 
Stacks Data structure.pptx
line24arts
 
Data Structures Stack and Queue Data Structures
poongothai11
 
Ad

More from Selvin Josy Bai Somu (8)

PDF
Client sidescripting javascript
Selvin Josy Bai Somu
 
PDF
Web technology
Selvin Josy Bai Somu
 
PPSX
Files in c++
Selvin Josy Bai Somu
 
PPSX
Constructor and destructor
Selvin Josy Bai Somu
 
PPSX
Inheritance
Selvin Josy Bai Somu
 
PPSX
Polymorphism
Selvin Josy Bai Somu
 
PPTX
Function overloading
Selvin Josy Bai Somu
 
PPSX
Basics of c++
Selvin Josy Bai Somu
 
Client sidescripting javascript
Selvin Josy Bai Somu
 
Web technology
Selvin Josy Bai Somu
 
Files in c++
Selvin Josy Bai Somu
 
Constructor and destructor
Selvin Josy Bai Somu
 
Polymorphism
Selvin Josy Bai Somu
 
Function overloading
Selvin Josy Bai Somu
 
Basics of c++
Selvin Josy Bai Somu
 

Recently uploaded (20)

PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Dimensions of Societal Planning in Commonism
StefanMz
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 

Data structure stack&queue basics

  • 1. DATA STRUCTURE STACKS AND QUEUES Prepared by : SELVIN JOSY BAI.S
  • 2. STACK  It is a linear data structure in which an elements may be inserted or deleted only at one end called the top of the stack.  This data structure implemented in LIFO (Last In First Out) manner  LIFO means element last inserted would be the first one to be deleted.  The Stack is also a dynamic data structure as it can grow or shrink.
  • 3.  Real life example :  A stack OF DISCS IN HOLDER  A stack of TOKENS IN HOLDER  Two basic operations of stack  PUSHING : An Insertion in a stack is called PUSHING.  POPPING : A Deletion from a stack is called POPPING.
  • 4. PUSHING ALGORITHM 1. Read ITEM 2. If TOP = N then Print “OVERFLOW” and Stop 3. Else set TOP = TOP + 1 //Creating a space for a new element 4. Set STACK [ TOP ] = ITEM //Inserting the new ITEM 5. Stop 1 2 3 4 5 TOP N 5 NULL
  • 5. POPPING ALGORITHM 1. If TOP = NULL then Print “UNDERFLOW” and return 2. Else set ITEM =STACK [ TOP ] 3. Set TOP = TOP - 1 4. Stop 1 2 3 4 5 TOP
  • 6. APPLICATIONS OF STACK  TO REVERSING A STRING  TO EVALUATE NOTATIONAL EXPRESSION(INFIX, PREFIX, & POSTFIX)  TO CONVERT FROM ONE EXPRESSION TO ANOTHER.
  • 7. QUEUE  It is a linear data structure in which an element may be inserted only at one end, called the REAR end and deletions can be take place at the other end, called the FRONT end.  This data structure implemented in FIFO (First In First Out) manner  FIFO means element first inserted would be the first one to be deleted.  The Queue is also a dynamic data structure as it can grow or shrink.  However, if additions and deletions are made at both ends of a queue, then such a queue is called Double Ended Queue or simply DEQUE.
  • 8. The following operations can be performed on Queues 1. Addition of an element at the REAR end of the queue 2. Deletion of an element from the FRONT end of the queue Real life example : • People waiting at a railway station counter for taking tickets
  • 9. Algorithm for INSERTION 1. If FRONT = 1 and REAR = N or If FRONT = REAR + 1 then Print “OVERFLOW” ; stop 2. if FRONT = NULL then set FRONT = 1 and REAR = 1 3. Else if REAR = N then set REAR = 1 4. Else set REAR = REAR + 1 5. Endif 6. Set QUEUE [ REAR ] = ITEM 7. Stop
  • 10. Algorithm for DELETION 1. If FRONT = NULL then Print “UNDERFLOW” ; stop 2. set ITEM = QUEUE [FRONT] 3. If FRONT = REAR then set FRONT = NULL and REAR = NULL 4. Else if FRONT = N then set FRONT = 1 5. Else set FRONT = FRONT + 1 6. Stop
  • 11. APPLICATIONS OF QUEUE  IT OCCURS IN THE JOB SCHEDULING  THE COMPUTER OS USE THIS CONCEPT IN SCHEDULING THE MEMORY, PROCESSOR AND THE FILES.  USED FOR SCHEDULING JOBS AND SERVICES.
  • 12. EXERCISE - 1  In CD pack, the CDs are placed one over the other through a central axis. Assume that there are 25 CDs in the pack. a. Name the data structure that resembles with the CD pack. b. Considering the CD pack as an array in C++, how will you name the position of the last CD and what will be its value? c. Write an algorithm to remove a CD from the pack and name the operation performed.
  • 13. EXERCISE - 2  While waiting for a ticket at the railway station ticket counter, you are following the principle as that of a data structure a. Name the data structure and the principle b. Write a C++ function to add a new element in this data structure. c. Name the situation where there is no space for adding new element
  • 14. Some more Questions 1. What is overflow and underflow? 2. Explain the terms PUSH and POP? 3. What are the applications of stacks and queues? 4. Name the data structure that resembles a person placing plates in a vessel. Write an algorithm for inserting a plate.