Professional Documents
Culture Documents
Compiled by Ms.V.Kala
Applications of stack
CONVERSION OF INFIX TO POSTFIX
EVALUATION OF POSTFIX EXPRESSION
RECURSION
Infix, Prefix and Postfix expressions
Prefix Postfix
Infix Expression Expression Expression
A+B +AB AB+
Prefix Postfix
Infix Expression Expression Expression
A+B*C+D ++A*BCD ABC*+D+
(A + B) * (C + D) *+AB+CD AB+CD+*
Examples of Infix, Prefix, and Postfix
expressions
Prefix Postfix
Infix Expression
Expression Expression
A+B+C+D
? ?
A*B+C*D
? ?
Solution -Examples of Infix, Prefix,
and Postfix Expressions
The first technique that we will consider uses the notion of a fully parenthesized expression.
A + B * C can be written as (A + (B * C)) to show explicitly that the multiplication has precedence over the
addition.
Moving Operators to the Right for Postfix Notation
3. When the input expression has been completely processed, check the
opstack. Any operators still on the stack can be removed and appended to
the end of the output list.
Example of Infix Expression to Postfix using stack
Evaluation of Postfix expression-Example
6 2 3 + -3 8 2 /+*2 $ 3+
Recursion
Recursion- If a function calls itself, it is
recursion (Example: Factorial of a number)
Recursion
What is a base condition in recursion?
In the recursive program, the solution to the base case is
provided and the solution of the bigger problem is expressed in
terms of smaller problems.