Using one of the stack implementations, write a method postfix that receives a string represent an expression in a
postfix notation, it evaluates that expression and returns the result.
postfix notation
72-
34+5*
345*+
37+82/-
34263/-*+
infix notation (fully parenthesized)
(7-2)
(3+4)*5)
(3 + (4*5))
((3+7) - (8/2))
(3+(4* (2-(6/3))))
The algorithm:
1- Read a string from user.
2- Create a stack to store double values.
3- Scan the string character by character till the end.
4- If the character represents a number (operand), push to the stack.
5- If the character represents an operator (+, -, *, /), pop two values from the stack and perform the
operation between them then push the result to the stack.
6- When the string finishes, the final result will be in the bottom of the stack, pop the result.
Note: This algorithm is operational ONLY with one-digit value (operand).
7-2
17-2 X