SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Stack
By
Nilesh Dalvi
Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College.
http://www.slideshare.net/nileshdalvi01
Java and DataJava and Data
StructuresStructures
Stack
• A Stack is a list of elements in which an element may
be inserted or deleted at one end which is known as
TOP of the stack.
• Operation Performed On Array:
1. Push: add an element in stack
2. Pop: remove an element in stack
3. Peek :Current processed element
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
a
b
c TOP
Array representation of stacks:
• We can represent a stack in computer in various ways, by
means of one-way-list or linear array.
• Consider Linear array stack:
• TOP : Location of the top element of the stack
• MAXSTK : max elements that can be held by stack
• If TOP = 0 or TOP = NULL indicates that stack is empty.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
XX YY ZZ
1 2 3 4 5 6 7 8
TOP MAXSTK
Adding element: PUSH()
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm PUSH (STACK, ITEM)
{
if (TOP = MAXSTK) then
write ("Overflow");
else
TOP := TOP + 1;
STACK [TOP] := ITEM;
}
Deleting element: POP()
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm POP (STACK, ITEM)
{
if (TOP = 0) then
write ("Underflow");
else
ITEM = STACK [TOP];
TOP := TOP - 1;
}
Accessing element: PEEK()
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm PEEK (STACK)
{
if (TOP = 0) then
write ("Underflow");
else
Return STACK [TOP];
}
Implementation of Stack operations
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Applications of Stack:
• Recursion
• Infix to postfix conversion
• Postfix to infix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
( a + b - c ) * d – ( e + f )
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Infix to postfix conversion
infixVect
postfixVect
a + b - c ) * d – ( e + f )
(
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
+ b - c ) * d – ( e + f )
(
a
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
b - c ) * d – ( e + f )
(
a
+
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
- c ) * d – ( e + f )
(
a b
+
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
c ) * d – ( e + f )
(
a b +
-
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
) * d – ( e + f )
(
a b + c
-
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
* d – ( e + f )
a b + c -
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
d – ( e + f )
a b + c -
*
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
– ( e + f )
a b + c - d
*
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
( e + f )
a b + c – d *
-
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
e + f )
a b + c – d *
-
(
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
+ f )
a b + c – d * e
-
(
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
f )
a b + c – d * e
-
(
+
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
)
a b + c – d * e f
-
(
+
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
a b + c – d * e f +
-
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
infixVect
postfixVect
a b + c – d * e f + -
Infix to postfix conversion
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm for Infix to Postfix
1) Examine the next element in the input.
2) If it is operand, output it.
3) If it is opening parenthesis, push it on stack.
4) If it is an operator, then
i) If stack is empty, push operator on stack.
ii) If the top of stack is opening parenthesis, push operator on stack
iii) If it has higher priority than the top of stack, push operator on stack.
iv) Else pop the operator from the stack and output it, repeat step 4
5) If it is a closing parenthesis, pop operators from stack and output them
until an opening parenthesis is encountered. pop and discard the opening
parenthesis.
6) If there is more input go to step 1
7) If there is no more input, pop the remaining operators to output.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Q & A

Weitere ähnliche Inhalte

Andere mochten auch

6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception HandlingNilesh Dalvi
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and IntefacesNilesh Dalvi
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and VariablesNilesh Dalvi
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in javaNilesh Dalvi
 
Chinese Cultural Entailment 中国文化蕴涵
Chinese Cultural Entailment  中国文化蕴涵Chinese Cultural Entailment  中国文化蕴涵
Chinese Cultural Entailment 中国文化蕴涵John Jeffery
 
TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o MalTDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o Maltdc-globalcode
 
Actividad de aprendizaje 2 SEGUNDO BLOQUE
Actividad de aprendizaje 2 SEGUNDO BLOQUEActividad de aprendizaje 2 SEGUNDO BLOQUE
Actividad de aprendizaje 2 SEGUNDO BLOQUEPaolachable
 
TDC2016SP - Desacoplando suas regras de negócio do Rails
TDC2016SP - Desacoplando suas regras de negócio do RailsTDC2016SP - Desacoplando suas regras de negócio do Rails
TDC2016SP - Desacoplando suas regras de negócio do Railstdc-globalcode
 
Como hacer una pagina en wix
Como hacer una pagina en wixComo hacer una pagina en wix
Como hacer una pagina en wixwiston98
 
TDC2016SP - Finanças Quantitativas com Python
TDC2016SP - Finanças Quantitativas com PythonTDC2016SP - Finanças Quantitativas com Python
TDC2016SP - Finanças Quantitativas com Pythontdc-globalcode
 
取是一種本事捨是一種智慧
取是一種本事捨是一種智慧取是一種本事捨是一種智慧
取是一種本事捨是一種智慧Jaing Lai
 
TDC2016SP - Groovy como você nunca viu
TDC2016SP - Groovy como você nunca viuTDC2016SP - Groovy como você nunca viu
TDC2016SP - Groovy como você nunca viutdc-globalcode
 
Blog diapocitiva ventajas y desventajas
Blog diapocitiva ventajas y desventajasBlog diapocitiva ventajas y desventajas
Blog diapocitiva ventajas y desventajasNELLYS29
 
Exposicion final
Exposicion finalExposicion final
Exposicion finalPerson0001
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seoJinTaek Seo
 

Andere mochten auch (19)

7. Multithreading
7. Multithreading7. Multithreading
7. Multithreading
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Chinese Cultural Entailment 中国文化蕴涵
Chinese Cultural Entailment  中国文化蕴涵Chinese Cultural Entailment  中国文化蕴涵
Chinese Cultural Entailment 中国文化蕴涵
 
TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o MalTDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
 
Actividad de aprendizaje 2 SEGUNDO BLOQUE
Actividad de aprendizaje 2 SEGUNDO BLOQUEActividad de aprendizaje 2 SEGUNDO BLOQUE
Actividad de aprendizaje 2 SEGUNDO BLOQUE
 
TDC2016SP - Desacoplando suas regras de negócio do Rails
TDC2016SP - Desacoplando suas regras de negócio do RailsTDC2016SP - Desacoplando suas regras de negócio do Rails
TDC2016SP - Desacoplando suas regras de negócio do Rails
 
Como hacer una pagina en wix
Como hacer una pagina en wixComo hacer una pagina en wix
Como hacer una pagina en wix
 
TDC2016SP - Finanças Quantitativas com Python
TDC2016SP - Finanças Quantitativas com PythonTDC2016SP - Finanças Quantitativas com Python
TDC2016SP - Finanças Quantitativas com Python
 
取是一種本事捨是一種智慧
取是一種本事捨是一種智慧取是一種本事捨是一種智慧
取是一種本事捨是一種智慧
 
Por que sua próxima aplicação web deve ser em Clojure?
Por que sua próxima aplicação web deve ser em Clojure?Por que sua próxima aplicação web deve ser em Clojure?
Por que sua próxima aplicação web deve ser em Clojure?
 
TDC2016SP - Groovy como você nunca viu
TDC2016SP - Groovy como você nunca viuTDC2016SP - Groovy como você nunca viu
TDC2016SP - Groovy como você nunca viu
 
Blog diapocitiva ventajas y desventajas
Blog diapocitiva ventajas y desventajasBlog diapocitiva ventajas y desventajas
Blog diapocitiva ventajas y desventajas
 
Exposicion final
Exposicion finalExposicion final
Exposicion final
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
Stack
StackStack
Stack
 

Ähnlich wie 12. Stack

Advanced data structures slide 2 2+
Advanced data structures slide 2 2+Advanced data structures slide 2 2+
Advanced data structures slide 2 2+jomerson remorosa
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending ClassesNilesh Dalvi
 
Daksh Sharma ,BCA 2nd Year
Daksh  Sharma ,BCA 2nd YearDaksh  Sharma ,BCA 2nd Year
Daksh Sharma ,BCA 2nd Yeardezyneecole
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structurefaran nawaz
 

Ähnlich wie 12. Stack (9)

Advanced data structures slide 2 2+
Advanced data structures slide 2 2+Advanced data structures slide 2 2+
Advanced data structures slide 2 2+
 
Chapter 6 ds
Chapter 6 dsChapter 6 ds
Chapter 6 ds
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
 
Stack Algorithm
Stack AlgorithmStack Algorithm
Stack Algorithm
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
stack & queue
stack & queuestack & queue
stack & queue
 
Daksh Sharma ,BCA 2nd Year
Daksh  Sharma ,BCA 2nd YearDaksh  Sharma ,BCA 2nd Year
Daksh Sharma ,BCA 2nd Year
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
 

Mehr von Nilesh Dalvi

1. Overview of Java
1. Overview of Java1. Overview of Java
1. Overview of JavaNilesh Dalvi
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsNilesh Dalvi
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops conceptsNilesh Dalvi
 

Mehr von Nilesh Dalvi (10)

2. Basics of Java
2. Basics of Java2. Basics of Java
2. Basics of Java
 
1. Overview of Java
1. Overview of Java1. Overview of Java
1. Overview of Java
 
Templates
TemplatesTemplates
Templates
 
File handling
File handlingFile handling
File handling
 
Strings
StringsStrings
Strings
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 

Kürzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
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
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
“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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Kürzlich hochgeladen (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
“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...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

12. Stack

  • 1. Stack By Nilesh Dalvi Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College. http://www.slideshare.net/nileshdalvi01 Java and DataJava and Data StructuresStructures
  • 2. Stack • A Stack is a list of elements in which an element may be inserted or deleted at one end which is known as TOP of the stack. • Operation Performed On Array: 1. Push: add an element in stack 2. Pop: remove an element in stack 3. Peek :Current processed element Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). a b c TOP
  • 3. Array representation of stacks: • We can represent a stack in computer in various ways, by means of one-way-list or linear array. • Consider Linear array stack: • TOP : Location of the top element of the stack • MAXSTK : max elements that can be held by stack • If TOP = 0 or TOP = NULL indicates that stack is empty. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). XX YY ZZ 1 2 3 4 5 6 7 8 TOP MAXSTK
  • 4. Adding element: PUSH() Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm PUSH (STACK, ITEM) { if (TOP = MAXSTK) then write ("Overflow"); else TOP := TOP + 1; STACK [TOP] := ITEM; }
  • 5. Deleting element: POP() Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm POP (STACK, ITEM) { if (TOP = 0) then write ("Underflow"); else ITEM = STACK [TOP]; TOP := TOP - 1; }
  • 6. Accessing element: PEEK() Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm PEEK (STACK) { if (TOP = 0) then write ("Underflow"); else Return STACK [TOP]; }
  • 7. Implementation of Stack operations Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 8. Applications of Stack: • Recursion • Infix to postfix conversion • Postfix to infix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 9. infixVect postfixVect ( a + b - c ) * d – ( e + f ) Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Infix to postfix conversion
  • 10. infixVect postfixVect a + b - c ) * d – ( e + f ) ( Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 11. infixVect postfixVect + b - c ) * d – ( e + f ) ( a Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 12. infixVect postfixVect b - c ) * d – ( e + f ) ( a + Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 13. infixVect postfixVect - c ) * d – ( e + f ) ( a b + Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 14. infixVect postfixVect c ) * d – ( e + f ) ( a b + - Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 15. infixVect postfixVect ) * d – ( e + f ) ( a b + c - Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 16. infixVect postfixVect * d – ( e + f ) a b + c - Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 17. infixVect postfixVect d – ( e + f ) a b + c - * Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 18. infixVect postfixVect – ( e + f ) a b + c - d * Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 19. infixVect postfixVect ( e + f ) a b + c – d * - Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 20. infixVect postfixVect e + f ) a b + c – d * - ( Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 21. infixVect postfixVect + f ) a b + c – d * e - ( Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 22. infixVect postfixVect f ) a b + c – d * e - ( + Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 23. infixVect postfixVect ) a b + c – d * e f - ( + Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 24. infixVect postfixVect a b + c – d * e f + - Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 25. infixVect postfixVect a b + c – d * e f + - Infix to postfix conversion Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 26. Algorithm for Infix to Postfix 1) Examine the next element in the input. 2) If it is operand, output it. 3) If it is opening parenthesis, push it on stack. 4) If it is an operator, then i) If stack is empty, push operator on stack. ii) If the top of stack is opening parenthesis, push operator on stack iii) If it has higher priority than the top of stack, push operator on stack. iv) Else pop the operator from the stack and output it, repeat step 4 5) If it is a closing parenthesis, pop operators from stack and output them until an opening parenthesis is encountered. pop and discard the opening parenthesis. 6) If there is more input go to step 1 7) If there is no more input, pop the remaining operators to output. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 27. Q & A