SlideShare a Scribd company logo
1 of 14
Stack
21EG101A53 SRIDHAR
21EG101A17 SANDEEP
21EG101A37 SHIVA K
21EG101A38 KRANTHI
21EG101A63 MAHI TEJ
21EG101A22 THIRUMALESH
1
What is a Stack
 Stack of Books
2
Stacks
 What is a Stack?
A stack is a data structure of
ordered items such that items
can be inserted and removed only
at one end.
3
Stacks
What can we do with a stack?
push - place an item on the
stack
peek - Look at the item on top
of the stack, but do not remove
it
pop - Look at the item on top of
the stack and remove it
4
Stacks
 A stack is a LIFO (Last-In/First-Out) data
structure
 A stack is sometimes also called a
pushdown store.
 What are some applications of stacks?
 Program execution
 Parsing
 Evaluating postfix expressions
5
Stacks
 Problem:
 What happens if we try to pop an item
off the stack when the stack is empty?
This is called a stack underflow.
The pop method needs some way of
telling us that this has happened.
In java we use the
java.util.EmptyStackException
6
Interface IStack
Interface Istack {
boolean empty();
void push(char c);
char pop();
char peek();
}
Using a IStack
 A balance of braces.
 (()) balanced braces
 ()(()()))) not balanced braces
 How can you use Istack to check a brace is balanced
or not?
When you implement the above
requirement, you ignore the
implementation details of Istack.
Implementing a Stack
 There are two ways we can implement a
stack:
 Using an array
 Using a linked list
9
Implementing a Stack
 Implementing a stack using an array is
fairly easy.
 The bottom of the stack is at data[0]
 The top of the stack is at
data[numItems-1]
 push onto the stack at data[numItems]
 pop off of the stack at data[numItems-
1]
10
Implementing a Stack
 Implementing a stack using a linked list isn’t that
bad either…
 Store the items in the stack in a linked list
 The top of the stack is the head node, the
bottom of the stack is the end of the list
 push by adding to the front of the list
 pop by removing from the front of the list
11
Reversing a Word
 We can use a stack to reverse the letters
in a word.
 How?
12
Reversing a Word
 Read each letter in the word and push it
onto the stack
 When you reach the end of the word, pop
the letters off the stack and print them
out.
13
THANK YOU

More Related Content

Similar to ppt.pptx (20)

My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
 
stacks2
stacks2stacks2
stacks2
 
Lecture5
Lecture5Lecture5
Lecture5
 
04 stacks
04 stacks04 stacks
04 stacks
 
DSA_Lecture4-Stack.pptx
DSA_Lecture4-Stack.pptxDSA_Lecture4-Stack.pptx
DSA_Lecture4-Stack.pptx
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-deques
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
LEC3-DS ALGO(updated).pdf
LEC3-DS  ALGO(updated).pdfLEC3-DS  ALGO(updated).pdf
LEC3-DS ALGO(updated).pdf
 
notes.pdf
notes.pdfnotes.pdf
notes.pdf
 
Team 3
Team 3Team 3
Team 3
 
Lesson 3 - Stack ADT.pdf
Lesson 3 - Stack ADT.pdfLesson 3 - Stack ADT.pdf
Lesson 3 - Stack ADT.pdf
 
Stacks
StacksStacks
Stacks
 
Stack
StackStack
Stack
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Stacks in data structure
Stacks  in data structureStacks  in data structure
Stacks in data structure
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 

Recently uploaded

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

ppt.pptx

  • 1. Stack 21EG101A53 SRIDHAR 21EG101A17 SANDEEP 21EG101A37 SHIVA K 21EG101A38 KRANTHI 21EG101A63 MAHI TEJ 21EG101A22 THIRUMALESH 1
  • 2. What is a Stack  Stack of Books 2
  • 3. Stacks  What is a Stack? A stack is a data structure of ordered items such that items can be inserted and removed only at one end. 3
  • 4. Stacks What can we do with a stack? push - place an item on the stack peek - Look at the item on top of the stack, but do not remove it pop - Look at the item on top of the stack and remove it 4
  • 5. Stacks  A stack is a LIFO (Last-In/First-Out) data structure  A stack is sometimes also called a pushdown store.  What are some applications of stacks?  Program execution  Parsing  Evaluating postfix expressions 5
  • 6. Stacks  Problem:  What happens if we try to pop an item off the stack when the stack is empty? This is called a stack underflow. The pop method needs some way of telling us that this has happened. In java we use the java.util.EmptyStackException 6
  • 7. Interface IStack Interface Istack { boolean empty(); void push(char c); char pop(); char peek(); }
  • 8. Using a IStack  A balance of braces.  (()) balanced braces  ()(()()))) not balanced braces  How can you use Istack to check a brace is balanced or not? When you implement the above requirement, you ignore the implementation details of Istack.
  • 9. Implementing a Stack  There are two ways we can implement a stack:  Using an array  Using a linked list 9
  • 10. Implementing a Stack  Implementing a stack using an array is fairly easy.  The bottom of the stack is at data[0]  The top of the stack is at data[numItems-1]  push onto the stack at data[numItems]  pop off of the stack at data[numItems- 1] 10
  • 11. Implementing a Stack  Implementing a stack using a linked list isn’t that bad either…  Store the items in the stack in a linked list  The top of the stack is the head node, the bottom of the stack is the end of the list  push by adding to the front of the list  pop by removing from the front of the list 11
  • 12. Reversing a Word  We can use a stack to reverse the letters in a word.  How? 12
  • 13. Reversing a Word  Read each letter in the word and push it onto the stack  When you reach the end of the word, pop the letters off the stack and print them out. 13