SlideShare a Scribd company logo
1 of 12
Asslam-o-Alaikum
M.Shahzeb (Reg#59)
Aqeel Badar (Reg#141)
Husnain Akram(Reg#49)
Stack
Stack and its operations: PUSH, POP
Representation of the states of stack
PUSH, POP algorithms
Stack application: prefix, infix, postfix computations
What is Stack?
 Stack is a storage structure that stores information in last in first out(LIFO)
manner. It means that the item stored at last is retrieved at first . Typically, stack is
a group of memory locations with a register that holds the address of topmost
element. This special register that points to top of stack is known as Stack
Pointer.
Stack Operations
Stack supports two operations:
Push:
 Inserts an item on top of stack.
 Causes stack to grow
 Stack pointer gets increment
0
1
2
3
4
5
SP
Empty
Full
A B C D E F
Stack is Full
Stack Operations
PUSH Algorithm
if !(FULL)
SP SP + 1
M[SP]  DR
If (SP = 5) then
FULL  1
EMPTY  0
else
Overflow
-1
Repeat the process until SP=5
Pop:
 Deletes an item from top of stack.
 Causes stack to shrink
 Stack pointer get decrement
Stack Operations
POP Algorithm
if !(EMPTY)
DR  M[SP]
SP SP- 1
If (SP = -1) then
FULL0
EMPTY 1
else
Underflow
0
1
2
3
4
5SP
Empty
Full
Stack Operations
-1
A
B
C
D
E
F
Stack is Empty
Repeat the process until SP=-1
Applications of stack
1. Expression Evaluation
2. Expression conversion
 Infix to Postfix
 Infix to Prefix
 Postfix to Infix
 Prefix to Infix
3. Parsing
4. Simulation of recursion
5. Function call
Some examples of infix, prefix and postfix
 Infix
Step by step evaluation of 3*2+5
Given 3*2+5-7
= 6+5-7
= 11-7
= 4
 Prefix
-+*3257
= - + 657
= -(11)7
= 4
Postfix
32*5+7-
= 65+7-
= (11)7-
= 4
Prefix Notation Algorithm
Scan from left to right
If (scanned= operation)
PUSH
Else
if (scanned =1stoperand)
PUSH
Else if (scanned = 2ndoperand)
POP
POP
Evaluate
PUSH.
0
1
2
3
4
5
Empty
Full
-1
+ * 3 4 * 5 6
= 12
Repeat the process
Notation
3042
Postfix Notation Algorithm
Scan from left to right
If (scanned=operand)
PUSH
Else
if (scanned=operator)
POP
POP
Evaluate
PUSH
0
1
2
3
4
5
Empty
Full
-1
3 4 * 5 6 * +Notation
=
Repeat the process
123042
Thank you

More Related Content

What's hot

Exercice.docx
Exercice.docxExercice.docx
Exercice.docximane26
 
Project of data structure
Project of data structureProject of data structure
Project of data structureUmme habiba
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operationSenthil Kumar
 
Csa stack
Csa stackCsa stack
Csa stackPCTE
 
Stacks and queue
Stacks and queueStacks and queue
Stacks and queueAmit Vats
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applicationsSaqib Saeed
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.CIIT Atd.
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 

What's hot (20)

Stacks queues
Stacks queuesStacks queues
Stacks queues
 
Exercice.docx
Exercice.docxExercice.docx
Exercice.docx
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Stack
StackStack
Stack
 
Csa stack
Csa stackCsa stack
Csa stack
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Stacks and queue
Stacks and queueStacks and queue
Stacks and queue
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
Stack
StackStack
Stack
 
stack presentation
stack presentationstack presentation
stack presentation
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
Stack queue
Stack queueStack queue
Stack queue
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Stack project
Stack projectStack project
Stack project
 
Stacks
StacksStacks
Stacks
 

Similar to STACK TITLE

Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptxSonaPathak4
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureYaksh Jethva
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with exampleNamanKikani
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data StructureUshaP15
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7Kumar
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxShivam Kumar
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptxline24arts
 
Explain what does the following function do void foo (Stack s) { .pdf
Explain what does the following function do  void foo (Stack s)  {  .pdfExplain what does the following function do  void foo (Stack s)  {  .pdf
Explain what does the following function do void foo (Stack s) { .pdfmeerobertsonheyde608
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfGirT2
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxSLekshmiNair
 
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
 

Similar to STACK TITLE (20)

Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
 
Stacks
StacksStacks
Stacks
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Explain what does the following function do void foo (Stack s) { .pdf
Explain what does the following function do  void foo (Stack s)  {  .pdfExplain what does the following function do  void foo (Stack s)  {  .pdf
Explain what does the following function do void foo (Stack s) { .pdf
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptx
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
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
 

Recently uploaded

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
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
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
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
 
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
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
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
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
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
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
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
 
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
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
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
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
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
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

STACK TITLE

  • 1. Asslam-o-Alaikum M.Shahzeb (Reg#59) Aqeel Badar (Reg#141) Husnain Akram(Reg#49)
  • 2. Stack Stack and its operations: PUSH, POP Representation of the states of stack PUSH, POP algorithms Stack application: prefix, infix, postfix computations
  • 3. What is Stack?  Stack is a storage structure that stores information in last in first out(LIFO) manner. It means that the item stored at last is retrieved at first . Typically, stack is a group of memory locations with a register that holds the address of topmost element. This special register that points to top of stack is known as Stack Pointer.
  • 4. Stack Operations Stack supports two operations: Push:  Inserts an item on top of stack.  Causes stack to grow  Stack pointer gets increment
  • 5. 0 1 2 3 4 5 SP Empty Full A B C D E F Stack is Full Stack Operations PUSH Algorithm if !(FULL) SP SP + 1 M[SP]  DR If (SP = 5) then FULL  1 EMPTY  0 else Overflow -1 Repeat the process until SP=5
  • 6. Pop:  Deletes an item from top of stack.  Causes stack to shrink  Stack pointer get decrement Stack Operations
  • 7. POP Algorithm if !(EMPTY) DR  M[SP] SP SP- 1 If (SP = -1) then FULL0 EMPTY 1 else Underflow 0 1 2 3 4 5SP Empty Full Stack Operations -1 A B C D E F Stack is Empty Repeat the process until SP=-1
  • 8. Applications of stack 1. Expression Evaluation 2. Expression conversion  Infix to Postfix  Infix to Prefix  Postfix to Infix  Prefix to Infix 3. Parsing 4. Simulation of recursion 5. Function call
  • 9. Some examples of infix, prefix and postfix  Infix Step by step evaluation of 3*2+5 Given 3*2+5-7 = 6+5-7 = 11-7 = 4  Prefix -+*3257 = - + 657 = -(11)7 = 4 Postfix 32*5+7- = 65+7- = (11)7- = 4
  • 10. Prefix Notation Algorithm Scan from left to right If (scanned= operation) PUSH Else if (scanned =1stoperand) PUSH Else if (scanned = 2ndoperand) POP POP Evaluate PUSH. 0 1 2 3 4 5 Empty Full -1 + * 3 4 * 5 6 = 12 Repeat the process Notation 3042
  • 11. Postfix Notation Algorithm Scan from left to right If (scanned=operand) PUSH Else if (scanned=operator) POP POP Evaluate PUSH 0 1 2 3 4 5 Empty Full -1 3 4 * 5 6 * +Notation = Repeat the process 123042