SlideShare a Scribd company logo
2
Most read
7
Most read
8
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

PPTX
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
PPT
Stacks
sweta dargad
 
PPSX
Stack
Seema Sharma
 
PPT
Skip list vinay khimsuriya_200430723005
vinaykhimsuriya1
 
PPTX
Stack using Linked List
Sayantan Sur
 
PPTX
Stack and Queue
Apurbo Datta
 
PPTX
Introduction to stack
vaibhav2910
 
PPTX
Stack and queue
CHANDAN KUMAR
 
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
Stacks
sweta dargad
 
Skip list vinay khimsuriya_200430723005
vinaykhimsuriya1
 
Stack using Linked List
Sayantan Sur
 
Stack and Queue
Apurbo Datta
 
Introduction to stack
vaibhav2910
 
Stack and queue
CHANDAN KUMAR
 

What's hot (20)

PPT
Stack
srihariyenduri
 
PPTX
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
PPTX
queue & its applications
somendra kumar
 
PDF
Applications of stack
eShikshak
 
PPTX
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
PPSX
Data Structure (Stack)
Adam Mukharil Bachtiar
 
PPTX
Stack project
Amr Aboelgood
 
PDF
Stack
Zaid Shabbir
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
Data Structures (CS8391)
Elavarasi K
 
PPTX
Queues in C++
Vineeta Garg
 
PPTX
Stack and its operations
V.V.Vanniaperumal College for Women
 
PPT
Stacks overview with its applications
Saqib Saeed
 
PPTX
Tree_Definition.pptx
sandeep54552
 
PPTX
Queues
Ashim Lamichhane
 
PDF
Python Collections Tutorial | Edureka
Edureka!
 
PPTX
Binary Tree Traversal
Dhrumil Panchal
 
PPTX
Unit I-Data structures stack & Queue
DrkhanchanaR
 
PPTX
sorting and its types
SIVASHANKARIRAJAN
 
PPT
Queue Data Structure
Zidny Nafan
 
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
queue & its applications
somendra kumar
 
Applications of stack
eShikshak
 
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
Data Structure (Stack)
Adam Mukharil Bachtiar
 
Stack project
Amr Aboelgood
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Data Structures (CS8391)
Elavarasi K
 
Queues in C++
Vineeta Garg
 
Stack and its operations
V.V.Vanniaperumal College for Women
 
Stacks overview with its applications
Saqib Saeed
 
Tree_Definition.pptx
sandeep54552
 
Python Collections Tutorial | Edureka
Edureka!
 
Binary Tree Traversal
Dhrumil Panchal
 
Unit I-Data structures stack & Queue
DrkhanchanaR
 
sorting and its types
SIVASHANKARIRAJAN
 
Queue Data Structure
Zidny Nafan
 
Ad

Viewers also liked (10)

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
 
PPT
Queue data structure
anooppjoseph
 
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
 
Queue data structure
anooppjoseph
 
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
stack data structure and its applications , advantages, disadvantages etc
rajinooka
 
PPT
stack data structure , applications, advantages
rajinooka
 
PPT
Linear Datsructure_stacks_Data Structure_PPT.ppt
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
 
stack data structure and its applications , advantages, disadvantages etc
rajinooka
 
stack data structure , applications, advantages
rajinooka
 
Linear Datsructure_stacks_Data Structure_PPT.ppt
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
 

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
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PDF
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
CDH. pptx
AneetaSharma15
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Trends in pediatric nursing .pptx
AneetaSharma15
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 

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.