Professional Documents
Culture Documents
Expression Evaluation
Stack is used to evaluate prefix, postfix and infix expressions.
Expression Conversion
An expression can be represented in prefix, postfix or infix notation. Stack can be used
to convert one form of expression to another.
Syntax Parsing
Many compilers use a stack for parsing the syntax of expressions, program blocks etc.
before translating into low level code.
Backtracking
Suppose we are finding a path for solving maze problem. We choose a path and after
following it we realize that it is wrong. Now we need to go back to the beginning of the
path to start with new path. This can be done with the help of stack.
Parenthesis Checking
Stack is used to check the proper opening and closing of parenthesis.
String Reversal
Stack is used to reverse a string. We push the characters of string one by one into
stack and then pop character from stack.
Function Call
Stack is used to keep information about the active functions or subroutines.
There are various other applications of stack. I have mentioned some of them.
Comment below if you found any mistake in above article.
Infix Nortation
Infix notation is commonly used in arithmetic formula or statements, the operators are
written in-between their operands.
Let’s assume the below
2 * (5 + 3) / 4
Output: 4
Approach: Use Stacks
We will use two stacks
Expression: 5 4 + 8 *
– Step 1: push 5
– Step 2: push 4
– Step 3: pop 4, pop 5, add, push 9
– Step 4: push 8
– Step 5: pop 8, pop 9, multiply, push 72
– Step 6: pop 72 – the result
→, V. (2020). Applications of Stack - The Crazy Programmer. Retrieved 21 February 2020, from
https://www.thecrazyprogrammer.com/2016/04/applications-of-stack.html