The compiler scans the expression either from left to right or from right to left. Consider the expression: a + b * c + d The compiler first scans the expression to evaluate the expression “b * c”, then again scan the expression to add “a” to it. The result is then added to “d” after another scan. The repeated scanning makes it very in-efficient. It is better to convert the expression to postfix (or prefix) form before evaluation. The corresponding expression in postfix form is: “a b c*+d+”. The postfix expressions can be evaluated easily using a stack. Implementation You have to implement the following functionality using stack which takes input of fully parenthesized infix expressions and convert it to postfix form. Sample Input: (((12+13)*(20-30))/(811+99)) Sample Output: (there is a single space in between each operator and operand) 12 13+20 30-*811 99+/ Hint:
The compiler scans the expression either from left to right or from right to left.
Consider the expression: a + b * c + d
The compiler first scans the expression to evaluate the expression “b * c”, then again scan the expression
to add “a” to it. The result is then added to “d” after another scan. The repeated scanning makes it very
in-efficient. It is better to convert the expression to postfix (or prefix) form before evaluation. The
corresponding expression in postfix form is: “a b c*+d+”. The postfix expressions can be evaluated easily
using a stack.
Implementation
You have to implement the following functionality using stack which takes input of fully parenthesized
infix expressions and convert it to postfix form.
Sample Input:
(((12+13)*(20-30))/(811+99))
Sample Output: (there is a single space in between each operator and operand)
12 13+20 30-*811 99+/
Hint:
Take input in an array of character arrays, where each index of the array is itself a character
array. Each index stores either starting bracket, closing bracket, an operator or an operand. The
maximum size of the array can be 100.
program in c++.

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









