Professional Documents
Culture Documents
Algorithm: Stacks
By
Dr. Richa Sharma
Assistant Professor
ITS Engineering College
Greater noida
1
Applications of Stacks
Reversing a string
Factorial Calculation
Parenthesis Checker
Stacks can be used to check the validity of parentheses in any algebraic
expression.
Associativity
A+B*C
A+(B*C) Parentheses for emphasis
A+D
A(D)+ Postfix Form
ABC*+
Postfix
Examples
Infix Postfix Evaluation
2-3*4+5 234*-5+ -5
(2 - 3) * (4 + 5) 23-45+* -9
Input : A * B + C / D
Output : + * A B/ C D
Output : *-A/BC-/AKL
Algorithm to convert Infix to postfix
expression
Suppose we want to convert 2*3/(2-1)+5*3 into Postfix form,