SlideShare a Scribd company logo
1 of 14
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

What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESSowmya Jyothi
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureYaksh Jethva
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTSoumen Santra
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueFarhanum Aziera
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 

What's hot (20)

Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
Linked List
Linked ListLinked List
Linked List
 
Data structures
Data structuresData structures
Data structures
 
Queues
QueuesQueues
Queues
 
single linked list
single linked listsingle linked list
single linked list
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 

Viewers also liked

Queue and stacks
Queue and stacksQueue and stacks
Queue and stacksgrahamwell
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....Shail Nakum
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
Presentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.pptPresentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.pptKawsar Ahmed
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 

Viewers also liked (9)

Queues
QueuesQueues
Queues
 
Queue
QueueQueue
Queue
 
Queue and stacks
Queue and stacksQueue and stacks
Queue and stacks
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queue
QueueQueue
Queue
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Presentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.pptPresentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.ppt
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 

Similar to Data structure stack&queue basics

Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Getachew Ganfur
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arorakulachihansraj
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queuestech4us
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptxline24arts
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7Kumar
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptxskilljiolms
 

Similar to Data structure stack&queue basics (20)

Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
04 stacks
04 stacks04 stacks
04 stacks
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Queue
QueueQueue
Queue
 
Stack in C.pptx
Stack in C.pptxStack in C.pptx
Stack in C.pptx
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
Stack
StackStack
Stack
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 

More from Selvin Josy Bai Somu (8)

Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
 
Web technology
Web technologyWeb technology
Web technology
 
Files in c++
Files in c++Files in c++
Files in c++
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
Inheritance
InheritanceInheritance
Inheritance
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

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.