2. 2
Applications Of Stack
Convert infix expression to postfix and prefix
expressions
Evaluate the postfix expression
Reverse a string
Check well-formed (nested) parenthesis
Reverse a string
Process subprogram function calls
Parse (analyze the structure) of computer programs
Simulate recursion
In computations like decimal to binary conversion
In Backtracking algorithms (often used in optimizations and
in games)
3. 3
Expression Evaluation And
Conversion
The most frequent application of stacks is in evaluation of
arithmetic expressions.
An arithmetic expression is made up of operands, operators,
and delimiters.
When higher level programming language came into
existence one of the major difficulty faced by computer scientists
was to generate machine language instruction, which would
properly evaluate any arithmetic expression.
4. 4
Expression Evaluation
To fix the order of evaluation, assign to each operator a priority
Because even though we write expression in parenthesis, still
we have a question in mind, about whether to evaluate which
one bracket first
Once the priorities are assigned then within any pairs of
parenthesis we can understand that operators with highest
priority are to be evaluated first
While evaluating expression usually the following operation
precedence is used
5. 5
The following operators are written is in descending
order of their precedence:
Exponentiation ^, Unary +, Unary –, and not ~
Multiplication * and division /
Addition + and subtraction –
<, £ , =, ¹, ³, >
AND
OR
6. 6
The Operators and priorities
Data Structures in C++ by Dr. Varsha Patil Oxferd Univercity
7. 7
Polish Notation and Expression Conversion
Polish Mathematician Han Lukasiewicz suggested a notation called
pPolish notation, which gives two alternatives to represent an
arithmetic expression, the notation are postfix and prefix notations
The fundamental property of Polish notation is that the order in
which the operations are to be performed is determined by the
positions of the operators and operands in the expression.
Hence the advantage is parenthesis is not required while writing
expressions in pPolish notation