SlideShare a Scribd company logo
INTRODUCTION
 What is Stack?
 Stack Representation
 ADT specification of Stack
 Operations on Stack
 Stack Overflow and Stack Underflow
 Implementing of Stack
 Prefix, Postfix, Infix Notation
 Polish Notation
 Precedence and Priority
 Applications
WHAT IS STACK??
 Stores a set of elements in a particular order.
 Stack is like a container of memory.
 Stack principle- LAST IN FIRST OUT(LIFO)
Examples:-
LAST IN FIRST OUT
STACK REPRESENTATION
ADT SPCIFICATIONS OF STACK
Operations:
 Make Empty
 Boolean Is Empty
 Boolean Is Full
 Push (Item Type new Item)
 Pop (Item Type& item) (or pop and top)
TOP
 A list with the restriction that insertion and deletion
can be performed only from one end is called top.
 If stack is empty, then top is at -1 position.
 If stack is not empty, then top is at last position(n-1).
PUSH OPERATION
 Stack is empty, top is at -1 position.
 Function: Adds new Item to the top of the stack.
 Preconditions: Stack has been initialized and is not full.
 Post conditions: new Item is at the top of the stack.
PSEUDO CODE IN C
Void push() {
int item;
printf(“Enter item to push”);
scanf(“%d”.&item);
if(top == max – 1) { // overflow condition
printf(“Stack overflow”);
}
else {
top = top + 1;
stack[top] = item;
}
}
PUSH OPERATION
POP OPERATION
 Stack is not empty, then top is at last position (n-1).
 Removes top Item from stack and returns it in item.
 Always done on the top of stack
 The top most element is deleted first
 Preconditions: Stack has been initialized and is not
empty.
 Post conditions: Top element has been removed from
stack and item is a copy of the removed element.
PSEUDO CODE IN C
Void pop () {
if(top == -1)
printf(“Stack underflow”);
else {
printf(“The deleted item is %d”,stack[top]);
top--;
}
}
POP OPERATION
STACK OVERFLOW
 The condition resulting from trying to push an element
onto a full stack.
 Top is at last position(n-1).
STACK UNDERFLOW
 The condition resulting from trying to pop an
empty stack.
 Top is at -1 position.
IMPLEMENTING OF STACK
Basics two choices:-
 Array
 Linked list
1) Array:-
Array is quick, but limited in size.
IMPLEMENTING OF STACK
2) Linked list:-
Linked List requires overhead to allocate, link,
unlink, and deallocate, but is not limited in size
INFIX EXPRESSION
 Operator is used in between operands.
 Example:-
POSTFIX EXPRESSION
 Operator is used after operands.
 Example:-
PREFIX EXPRESSION
 Operator is used before operands.
 Example:-
POLISH NOTATION
 Prefix notation requires that all operators precede the two
operands that they work on.
 Postfix notation requires that its operators come after the
corresponding operands.
PRECEDENCE AND PRIORITY
INFIX TO POSTFIX
 The infix string from left to right.
 Initialize an empty stack.
 Character is an operand, add it to the Postfix
string.
 If the stack is empty, push the character is an
operator to stack
 stack is not empty, compare the precedence of
the character with the element on top of the
stack.
EXAMPLE OF INFIX TO
POSTFIX
INFIX TO PREFIX
 Reverse given prefix expression.
 Conversion same as infix to postfix expression.
 Reverse the expression.
EXAMPLE OF INFIX TO
PREFIX
EVALUATION OF POSTFIX
 Create a stack to store operands (or values).
 If the element is a number, push it into the stack.
 If the element is a operator, pop operands for the operator
from stack.
 Evaluate the operator and push the result back to the stack
when the expression is ended, the number in the stack is
the final answer.
EXAMPLE OF EVALUATION
OF POSTFIX
EVALUATION OF PREFIX
 Accept a prefix string from the user.
 The string from the right one character at a time.
 If it is an operand, push it in stack.
 If it is an operator, pop and perform the operation,
specified by the operator.
 Push the result in the stack.
 The number in stack is final answer.
EXAMPLE OF
EVALUATION OF PREFIX
APPLICATIONS
 Parsing
 Recursive Function
 Calling Function
 Expression Evaluation
 Expression Conversion
 Infix to Postfix
 Infix to Prefix
 Postfix to Infix
 Prefix to Infix
DATA STRUCTURE - STACK

More Related Content

What's hot (20)

PPTX
Queue
Raj Sarode
 
PPT
Stacks
Malainine Zaid
 
PPT
Priority queues
Priyanka Rana
 
PPTX
Ppt on Linked list,stack,queue
Srajan Shukla
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
Queues
Ashim Lamichhane
 
PPT
stack presentation
Shivalik college of engineering
 
PPTX
Data Structures (CS8391)
Elavarasi K
 
PPT
Queue Data Structure
Lovely Professional University
 
PPT
Depth First Search ( DFS )
Sazzad Hossain
 
DOCX
Stack - Operations and Applications
Sagacious IT Solution
 
PPT
Queue in Data Structure
Muhazzab Chouhadry
 
PPTX
Stack and its operations
V.V.Vanniaperumal College for Women
 
PPTX
Bubble sort | Data structure |
MdSaiful14
 
PPTX
Queue - Data Structure - Notes
Omprakash Chauhan
 
PPTX
Java Stack Data Structure.pptx
vishal choudhary
 
PPTX
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
PPTX
Binary Tree in Data Structure
Meghaj Mallick
 
PPT
Queue implementation
Rajendran
 
Queue
Raj Sarode
 
Priority queues
Priyanka Rana
 
Ppt on Linked list,stack,queue
Srajan Shukla
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Data Structures (CS8391)
Elavarasi K
 
Queue Data Structure
Lovely Professional University
 
Depth First Search ( DFS )
Sazzad Hossain
 
Stack - Operations and Applications
Sagacious IT Solution
 
Queue in Data Structure
Muhazzab Chouhadry
 
Stack and its operations
V.V.Vanniaperumal College for Women
 
Bubble sort | Data structure |
MdSaiful14
 
Queue - Data Structure - Notes
Omprakash Chauhan
 
Java Stack Data Structure.pptx
vishal choudhary
 
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
Binary Tree in Data Structure
Meghaj Mallick
 
Queue implementation
Rajendran
 

Similar to DATA STRUCTURE - STACK (20)

PPTX
Unit 3 stack
Dabbal Singh Mahara
 
PPTX
Stacks and queues using aaray line .pptx
ramkumar649780
 
PPTX
Data structure Stack
Praveen Vishwakarma
 
PPTX
stack data structure jnv chandrpur maharastra.pptx
PradeepVithule
 
PPT
Stack in Data Structure
Usha P
 
PPTX
DS-UNIT 3 FINAL.pptx
prakashvs7
 
PDF
Data Structures And Algorithms(stacks queues)
lahariit406
 
PPT
week 7,8,10,11 alll files included from .ppt
LidetAdmassu
 
PPTX
Introduction to information about Data Structure.pptx
tarrebulehora
 
PPTX
Stack data structure
rogineojerio020496
 
PPT
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
PPT
Unit 3 stack
kalyanineve
 
PPTX
Unit II - LINEAR DATA STRUCTURES
Usha Mahalingam
 
PPTX
Stacks Data structure.pptx
line24arts
 
PPTX
Stack ADT
MrsKArunasakthiCSE22
 
PDF
Stacks
Sadaf Ismail
 
PDF
Stack
Zaid Shabbir
 
PPTX
Project on stack Data structure
Soham Nanekar
 
PPTX
Stack,queue and linked list data structure.pptx
yukti266975
 
PPTX
dsppt-141121224848-conversion01 (1).pptx
zoobiarana76
 
Unit 3 stack
Dabbal Singh Mahara
 
Stacks and queues using aaray line .pptx
ramkumar649780
 
Data structure Stack
Praveen Vishwakarma
 
stack data structure jnv chandrpur maharastra.pptx
PradeepVithule
 
Stack in Data Structure
Usha P
 
DS-UNIT 3 FINAL.pptx
prakashvs7
 
Data Structures And Algorithms(stacks queues)
lahariit406
 
week 7,8,10,11 alll files included from .ppt
LidetAdmassu
 
Introduction to information about Data Structure.pptx
tarrebulehora
 
Stack data structure
rogineojerio020496
 
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
Unit 3 stack
kalyanineve
 
Unit II - LINEAR DATA STRUCTURES
Usha Mahalingam
 
Stacks Data structure.pptx
line24arts
 
Stacks
Sadaf Ismail
 
Project on stack Data structure
Soham Nanekar
 
Stack,queue and linked list data structure.pptx
yukti266975
 
dsppt-141121224848-conversion01 (1).pptx
zoobiarana76
 
Ad

More from Devyani Chaudhari (6)

PPTX
Online Education.pptx
Devyani Chaudhari
 
PPTX
PASSWORD SECURITY BASED ON HONEYWORD
Devyani Chaudhari
 
PPTX
Troubleshooting methods of computer peripherals
Devyani Chaudhari
 
PPTX
Elastic Block Storage (EBS)
Devyani Chaudhari
 
PPTX
INTRODUCTION TO ARDUINO & RASPBERRY, SENSOR AND TEMPERATURE INTERAFCING
Devyani Chaudhari
 
Online Education.pptx
Devyani Chaudhari
 
PASSWORD SECURITY BASED ON HONEYWORD
Devyani Chaudhari
 
Troubleshooting methods of computer peripherals
Devyani Chaudhari
 
Elastic Block Storage (EBS)
Devyani Chaudhari
 
INTRODUCTION TO ARDUINO & RASPBERRY, SENSOR AND TEMPERATURE INTERAFCING
Devyani Chaudhari
 
Ad

Recently uploaded (20)

PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
CHILD RIGHTS AND PROTECTION QUESTION BANK
Dr Raja Mohammed T
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
Quarter1-English3-W4-Identifying Elements of the Story
FLORRACHELSANTOS
 
DOCX
A summary of SPRING SILKWORMS by Mao Dun.docx
maryjosie1
 
PDF
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
PDF
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PDF
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
CHILD RIGHTS AND PROTECTION QUESTION BANK
Dr Raja Mohammed T
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Quarter1-English3-W4-Identifying Elements of the Story
FLORRACHELSANTOS
 
A summary of SPRING SILKWORMS by Mao Dun.docx
maryjosie1
 
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 

DATA STRUCTURE - STACK

  • 1. INTRODUCTION  What is Stack?  Stack Representation  ADT specification of Stack  Operations on Stack  Stack Overflow and Stack Underflow  Implementing of Stack  Prefix, Postfix, Infix Notation  Polish Notation  Precedence and Priority  Applications
  • 2. WHAT IS STACK??  Stores a set of elements in a particular order.  Stack is like a container of memory.  Stack principle- LAST IN FIRST OUT(LIFO) Examples:-
  • 5. ADT SPCIFICATIONS OF STACK Operations:  Make Empty  Boolean Is Empty  Boolean Is Full  Push (Item Type new Item)  Pop (Item Type& item) (or pop and top)
  • 6. TOP  A list with the restriction that insertion and deletion can be performed only from one end is called top.  If stack is empty, then top is at -1 position.  If stack is not empty, then top is at last position(n-1).
  • 7. PUSH OPERATION  Stack is empty, top is at -1 position.  Function: Adds new Item to the top of the stack.  Preconditions: Stack has been initialized and is not full.  Post conditions: new Item is at the top of the stack.
  • 8. PSEUDO CODE IN C Void push() { int item; printf(“Enter item to push”); scanf(“%d”.&item); if(top == max – 1) { // overflow condition printf(“Stack overflow”); } else { top = top + 1; stack[top] = item; } }
  • 10. POP OPERATION  Stack is not empty, then top is at last position (n-1).  Removes top Item from stack and returns it in item.  Always done on the top of stack  The top most element is deleted first  Preconditions: Stack has been initialized and is not empty.  Post conditions: Top element has been removed from stack and item is a copy of the removed element.
  • 11. PSEUDO CODE IN C Void pop () { if(top == -1) printf(“Stack underflow”); else { printf(“The deleted item is %d”,stack[top]); top--; } }
  • 13. STACK OVERFLOW  The condition resulting from trying to push an element onto a full stack.  Top is at last position(n-1).
  • 14. STACK UNDERFLOW  The condition resulting from trying to pop an empty stack.  Top is at -1 position.
  • 15. IMPLEMENTING OF STACK Basics two choices:-  Array  Linked list 1) Array:- Array is quick, but limited in size.
  • 16. IMPLEMENTING OF STACK 2) Linked list:- Linked List requires overhead to allocate, link, unlink, and deallocate, but is not limited in size
  • 17. INFIX EXPRESSION  Operator is used in between operands.  Example:-
  • 18. POSTFIX EXPRESSION  Operator is used after operands.  Example:-
  • 19. PREFIX EXPRESSION  Operator is used before operands.  Example:-
  • 20. POLISH NOTATION  Prefix notation requires that all operators precede the two operands that they work on.  Postfix notation requires that its operators come after the corresponding operands.
  • 22. INFIX TO POSTFIX  The infix string from left to right.  Initialize an empty stack.  Character is an operand, add it to the Postfix string.  If the stack is empty, push the character is an operator to stack  stack is not empty, compare the precedence of the character with the element on top of the stack.
  • 23. EXAMPLE OF INFIX TO POSTFIX
  • 24. INFIX TO PREFIX  Reverse given prefix expression.  Conversion same as infix to postfix expression.  Reverse the expression.
  • 25. EXAMPLE OF INFIX TO PREFIX
  • 26. EVALUATION OF POSTFIX  Create a stack to store operands (or values).  If the element is a number, push it into the stack.  If the element is a operator, pop operands for the operator from stack.  Evaluate the operator and push the result back to the stack when the expression is ended, the number in the stack is the final answer.
  • 28. EVALUATION OF PREFIX  Accept a prefix string from the user.  The string from the right one character at a time.  If it is an operand, push it in stack.  If it is an operator, pop and perform the operation, specified by the operator.  Push the result in the stack.  The number in stack is final answer.
  • 30. APPLICATIONS  Parsing  Recursive Function  Calling Function  Expression Evaluation  Expression Conversion  Infix to Postfix  Infix to Prefix  Postfix to Infix  Prefix to Infix