Lab 02 - StacksQueues - Bis
Lab 02 - StacksQueues - Bis
Given an infix expression in the form of a string str. Convert this infix expression to postfix
expression.
- Infix expression: The expression of the form A op B. When an operator is in-between
every pair of operands.
- Postfix expression: The expression of the form A B op. When an operator is followed for
every pair of operands.
Example:
- Input - Infix expression: A+B*(C^D-E)^(F+G*H)-I
Output - Postfix expression: ABCD^E-FGH*+^*+I-
- Input - Infix expression: A*(B+C)/D
Output - Postfix expression: ABC+*D/
Problem 3. Write a program to convert a postfix expression to infix.
Example:
- Input – Postfix expression: ABC++
- Output – Infix expression: (A+(B+C))
- Input – Postfix expression: AB*C+
- Output – Infix expression: ((A*B)+C)
Problem 4. Write a program to evaluate a prefix expression.
- Prefix expression: The expression of the form op A B. When an operator is before for
every pair of operands.
Give a prefix expression, the task is to evaluate the expression and print the final value. Operators
will only include the basic arithmetic operators like *, /, + and -.
Example:
- Input: - + 7 * 4 5 + 2 0
- Output: 25