Applications of STACK
Presented By:-
Yadraj Meena
K.V. INS KALINGA
 In computer science, a stack is an abstract data type
based on principle of(LIFO) that serves as a collection
of elements, with two principal operations: push,
which adds an element to the collection, and pop,
which removes the most recently added element.
 Functions necessary to implement a stack :
#include<iostream.h>
#define STACK_SIZE 20
int stack[STACK_SIZE]; /*space for stacking
integers*/
int top=-1; / *top_of_stack is
defined as global
variable for a global stack */
/*Function to check whether the stack is ‘full’ */
int stack_full()
{
if(top==STACK_SIZE-1)
return(1);
else
return(0);
}
 /* Function to check whether the stack is ‘empty’ */
int stack_empty()
{
if(top==-1)
return(1);
else
return(0);
}
/*Function to push or add an element on the stack.*/
void push(int number)
{
stack[++top]=number; /*add element on top of
stack */
}
 /* Function to pop an element from the stack*/
int pop()
{
int number;
number=stack[top]; /*remove top element from
stack */
top--;
return(number);
}
1. INFIX TO POSTFIX CONVERSION
2. EVALUATION OF POSTFIX EXPRESSION
 Infix notation is the common arithmetic and logical
formula notation, in which operators are written infix-
style between the operands they act on
 E.g. A + B
 In Postfix notation, the operator comes after the
Operand.
 For example, the Infix expression A+B will be written as
AB+ in its Postfix Notation.
 Postfix is also called ‘Reverse Polish Notation’
 In Prefix notation, the operator comes before the
operand.
 The Infix expression A+B will be written as +AB in its
Prefix Notation.
 Prefix is also called ‘Polish Notation’
ARITHMETIC OPERATORS Precedence
Exponentiation( ^ or ↑ ) HIGHEST
Multiplication and Division ( * , / ) MIDDLE
Addition and Subtraction ( + , - ) LOWEST
LOGICAL OPERATORS
NOT HIGHEST
AND MIDDLE
OR LOWEST
Algorithm: Infix to Postfix conversion
1. Enclose the expression in parentheses, that is, ( ).
2. Read next symbol of expression and repeat step 3 to 6 until
STACK is empty.
3. If the symbol is operand add to Postfix Expression
4.If the symbol read is ‘(‘ then push it into STACK.
5. If symbol read = operator then
(1) Repeat while ( Precedence of TOP(STACK)
>= precedence of
operator read)
{ POP operator from STACK and add operator to PE}
(2) Push operator into STACK
6. If the symbol read is ‘)’ then
(1) Repeat while( TOP[Stack] != ‘(‘ )
{ POP operator from stack and add to PE}
(2) Remove the ‘(‘ . [ it must not be added to PE ]
7. PE is the desired equivalent Postfix Expression
8. End
( A B+ (* -C /)D )E
(
A ( A
+ (+ A
B (+ AB
* (+* AB
( (+*( AB
C (+*( ABC
- (+*(- ABC
D (+*(- ABCD
) (+* ABCD-
/ (+/ ABCD-*
E (+/ ABCD-*E
) ABCD-*E/+
Scanned Element STACK OUTPUT(PE)
(
OUTPUT : ABCD-*E/+
 Convert infix to Postfix:
 ( A * B + ( C – D / E ))
( A * +B C( D- F/ ) )
Scanned Element STACK OUTPUT(PE)
( (
A ( A
* (* A
B (* AB
+ (+ AB*
( (+( AB*
C (+( AB*C
- (+(- AB*C
D (+(- AB*CD
/ (+(-/ AB*CD
F (+(-/ AB*CDF
) (+ AB*CDF/-
) AB+CDF/-+
OUTPUT : AB+CDF/-+
 Algorithm Steps
1. Create an empty stack STACK
2. Read next symbol of the Postfix expression PE and repeat
steps 3 and 4 until end of the expression is reached.
3. If(symbol read = operand) then PUSH(STACK , Symbol read)
4. If(symbol read = operator) then
{ if(operator = unary operator)
{ POP(Stack, symbol)
Evaluate the expression so formed and PUSH
the result onto STACK }
else
{ POP(STACK, symbol1)
POP(STACK, symbol 2)
Evaluate result = symbol2 operator symbol1
PUSH(STACK, result) }
}
5. POP(STACK, result)
6. End
Evaluate: 50 , 60 , + , 20 , 10 , - , *
OUTPUT : 1100
Scanned
Element
Operation Stack
Status
50 Push 50
60 Push 50, 60
+ Pop twice, 50 + 60 = 110
Push result
110
20 Push 110, 20
10 Push 110,20,10
- Pop twice, 20 – 10 =10
Push result
110,10
* Pop twice, 110 * 10 = 1100
Push result
1100
Evaluate the expression:
 True, False, NOT, AND ,False ,True ,OR ,
AND
Evaluate: True, False, NOT, AND ,False ,True ,OR , AND
OUTPUT: True
Scanned
Element
Operation Stack Status
True Push True
False Push True, False
NOT Pop one element and apply NOT operation
And Push the result into stack
True, True
AND True
False Push True, False
True Push True, False
True
OR True, True
AND True
Pop one element and apply AND operation
And Push the result into stack
Pop one element and apply OR operation
And Push the result into stack
Pop one element and apply AND operation
And Push the result into stack
THANKS…..
YOU

More Related Content

PPTX
Application of Stack - Yadraj Meena
PPSX
Stacks Implementation and Examples
PPT
Conversion of Infix To Postfix Expressions
PPTX
Stack and queue
PDF
Applications of stack
PPT
PPTX
Stack and its operations
PPTX
Unit 3 stack
Application of Stack - Yadraj Meena
Stacks Implementation and Examples
Conversion of Infix To Postfix Expressions
Stack and queue
Applications of stack
Stack and its operations
Unit 3 stack

What's hot (19)

PPT
Stack Operation In Data Structure
PPTX
Data structure Stack
PPTX
Stacks in c++
PPT
Infix to Postfix Conversion Using Stack
PPT
Stacks
PPT
Stack application
PPTX
Stack data structure
PPSX
PPTX
stack
PPTX
Polish
PPTX
Stacks in DATA STRUCTURE
PPT
PPTX
Introduction to stack
PPTX
Stack of Data structure
PPT
Stack Data Structure V1.0
PDF
PPTX
Stack - Data Structure
PPTX
Stack and its Applications : Data Structures ADT
PPTX
stacks and queues
Stack Operation In Data Structure
Data structure Stack
Stacks in c++
Infix to Postfix Conversion Using Stack
Stacks
Stack application
Stack data structure
stack
Polish
Stacks in DATA STRUCTURE
Introduction to stack
Stack of Data structure
Stack Data Structure V1.0
Stack - Data Structure
Stack and its Applications : Data Structures ADT
stacks and queues
Ad

Viewers also liked (18)

PDF
Vtecx20151216 2
PDF
2010SanteAwardsWinnersPressReleasel
PPTX
Enhancing Relevancy & User Experience with #SharePoint Search sps-philly 2015
TXT
Arial9
DOCX
Aramara
PDF
Vtecx20151216
PDF
Spm Pics
PPTX
01
 
PPTX
PPT
Cyber crime
PDF
Enhancing Relevancy & User Experience with SharePoint Search - SPSBMORE 2015
PDF
Vtecxlt20151201
PPTX
SPSNYC - Next Generation Portals
DOCX
Observacion de una clase
PPTX
Lead magnets: getting more prospects on your email list
PDF
ACMで作成するSSL証明書の活用
PPTX
The power of social proof
DOCX
Informe de observación en la escuela primaria
Vtecx20151216 2
2010SanteAwardsWinnersPressReleasel
Enhancing Relevancy & User Experience with #SharePoint Search sps-philly 2015
Arial9
Aramara
Vtecx20151216
Spm Pics
01
 
Cyber crime
Enhancing Relevancy & User Experience with SharePoint Search - SPSBMORE 2015
Vtecxlt20151201
SPSNYC - Next Generation Portals
Observacion de una clase
Lead magnets: getting more prospects on your email list
ACMで作成するSSL証明書の活用
The power of social proof
Informe de observación en la escuela primaria
Ad

Similar to Applicationofstack by Ali F.RAshid (20)

PDF
Data structure lab manual
PPT
Unit 3 stack
PPT
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
PDF
The concept of stack is extremely important in computer science and .pdf
PPTX
Data strutcure and annalysis topic stack
PPTX
Introduction to information about Data Structure.pptx
PPTX
Lec5-Stack-bukc-28022024-112316am (1) .pptx
PPTX
Stack and its applications
PPT
Data structure lecture7
PDF
Data structures stacks
PDF
Stacks,queues,linked-list
PDF
PPTX
Stack.pptx
PPTX
Stack - Data Structure - Notes
PDF
Data Structures And Algorithms(stacks queues)
PPT
PPTX
Data structure by Digvijay
PPTX
Stacks and queues using aaray line .pptx
PPTX
Data Structures and Agorithm: DS 06 Stack.pptx
Data structure lab manual
Unit 3 stack
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
The concept of stack is extremely important in computer science and .pdf
Data strutcure and annalysis topic stack
Introduction to information about Data Structure.pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Stack and its applications
Data structure lecture7
Data structures stacks
Stacks,queues,linked-list
Stack.pptx
Stack - Data Structure - Notes
Data Structures And Algorithms(stacks queues)
Data structure by Digvijay
Stacks and queues using aaray line .pptx
Data Structures and Agorithm: DS 06 Stack.pptx

Recently uploaded (20)

PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Empowerment Technology for Senior High School Guide
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
IGGE1 Understanding the Self1234567891011
PPTX
History, Philosophy and sociology of education (1).pptx
Unit 4 Computer Architecture Multicore Processor.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Empowerment Technology for Senior High School Guide
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Weekly quiz Compilation Jan -July 25.pdf
What if we spent less time fighting change, and more time building what’s rig...
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
TNA_Presentation-1-Final(SAVE)) (1).pptx
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Introduction to pro and eukaryotes and differences.pptx
IGGE1 Understanding the Self1234567891011
History, Philosophy and sociology of education (1).pptx

Applicationofstack by Ali F.RAshid

  • 1. Applications of STACK Presented By:- Yadraj Meena K.V. INS KALINGA
  • 2.  In computer science, a stack is an abstract data type based on principle of(LIFO) that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element.
  • 3.  Functions necessary to implement a stack : #include<iostream.h> #define STACK_SIZE 20 int stack[STACK_SIZE]; /*space for stacking integers*/ int top=-1; / *top_of_stack is defined as global variable for a global stack */ /*Function to check whether the stack is ‘full’ */ int stack_full() { if(top==STACK_SIZE-1) return(1); else return(0); }
  • 4.  /* Function to check whether the stack is ‘empty’ */ int stack_empty() { if(top==-1) return(1); else return(0); } /*Function to push or add an element on the stack.*/ void push(int number) { stack[++top]=number; /*add element on top of stack */ }
  • 5.  /* Function to pop an element from the stack*/ int pop() { int number; number=stack[top]; /*remove top element from stack */ top--; return(number); }
  • 6. 1. INFIX TO POSTFIX CONVERSION 2. EVALUATION OF POSTFIX EXPRESSION
  • 7.  Infix notation is the common arithmetic and logical formula notation, in which operators are written infix- style between the operands they act on  E.g. A + B
  • 8.  In Postfix notation, the operator comes after the Operand.  For example, the Infix expression A+B will be written as AB+ in its Postfix Notation.  Postfix is also called ‘Reverse Polish Notation’
  • 9.  In Prefix notation, the operator comes before the operand.  The Infix expression A+B will be written as +AB in its Prefix Notation.  Prefix is also called ‘Polish Notation’
  • 10. ARITHMETIC OPERATORS Precedence Exponentiation( ^ or ↑ ) HIGHEST Multiplication and Division ( * , / ) MIDDLE Addition and Subtraction ( + , - ) LOWEST LOGICAL OPERATORS NOT HIGHEST AND MIDDLE OR LOWEST
  • 11. Algorithm: Infix to Postfix conversion 1. Enclose the expression in parentheses, that is, ( ). 2. Read next symbol of expression and repeat step 3 to 6 until STACK is empty. 3. If the symbol is operand add to Postfix Expression 4.If the symbol read is ‘(‘ then push it into STACK. 5. If symbol read = operator then (1) Repeat while ( Precedence of TOP(STACK) >= precedence of operator read) { POP operator from STACK and add operator to PE} (2) Push operator into STACK 6. If the symbol read is ‘)’ then (1) Repeat while( TOP[Stack] != ‘(‘ ) { POP operator from stack and add to PE} (2) Remove the ‘(‘ . [ it must not be added to PE ] 7. PE is the desired equivalent Postfix Expression 8. End
  • 12. ( A B+ (* -C /)D )E ( A ( A + (+ A B (+ AB * (+* AB ( (+*( AB C (+*( ABC - (+*(- ABC D (+*(- ABCD ) (+* ABCD- / (+/ ABCD-* E (+/ ABCD-*E ) ABCD-*E/+ Scanned Element STACK OUTPUT(PE) ( OUTPUT : ABCD-*E/+
  • 13.  Convert infix to Postfix:  ( A * B + ( C – D / E ))
  • 14. ( A * +B C( D- F/ ) ) Scanned Element STACK OUTPUT(PE) ( ( A ( A * (* A B (* AB + (+ AB* ( (+( AB* C (+( AB*C - (+(- AB*C D (+(- AB*CD / (+(-/ AB*CD F (+(-/ AB*CDF ) (+ AB*CDF/- ) AB+CDF/-+ OUTPUT : AB+CDF/-+
  • 15.  Algorithm Steps 1. Create an empty stack STACK 2. Read next symbol of the Postfix expression PE and repeat steps 3 and 4 until end of the expression is reached. 3. If(symbol read = operand) then PUSH(STACK , Symbol read) 4. If(symbol read = operator) then { if(operator = unary operator) { POP(Stack, symbol) Evaluate the expression so formed and PUSH the result onto STACK } else { POP(STACK, symbol1) POP(STACK, symbol 2) Evaluate result = symbol2 operator symbol1 PUSH(STACK, result) } } 5. POP(STACK, result) 6. End
  • 16. Evaluate: 50 , 60 , + , 20 , 10 , - , * OUTPUT : 1100 Scanned Element Operation Stack Status 50 Push 50 60 Push 50, 60 + Pop twice, 50 + 60 = 110 Push result 110 20 Push 110, 20 10 Push 110,20,10 - Pop twice, 20 – 10 =10 Push result 110,10 * Pop twice, 110 * 10 = 1100 Push result 1100
  • 17. Evaluate the expression:  True, False, NOT, AND ,False ,True ,OR , AND
  • 18. Evaluate: True, False, NOT, AND ,False ,True ,OR , AND OUTPUT: True Scanned Element Operation Stack Status True Push True False Push True, False NOT Pop one element and apply NOT operation And Push the result into stack True, True AND True False Push True, False True Push True, False True OR True, True AND True Pop one element and apply AND operation And Push the result into stack Pop one element and apply OR operation And Push the result into stack Pop one element and apply AND operation And Push the result into stack