evaluate the following post fix expression. 50,5,/,5,1 ,*,5,-,+
Answers
Answer:15
Explanation:
Answer:
Given postfix expression: 50 , 5 , / , 5 , 1 , * , 5 , - , +
Stack = empty
First character : 50 (operand) (push to stack)
Stack = 50
Second character : 5 (operand) (push to stack)
Stack = 50 , 5
Third character : / (operator) (pop top two operands, solve and push back to stack)
Stack = empty
50 / 5 = 10 (push to stack)
Stack = 10
Fourth character : 5 (operand) (push to stack)
Stack = 10 , 5
Fifth character : 1 (operand) (push to stack)
Stack = 10 , 5 , 1
Sixth character : * (operator) (pop top two operands, solve and push back to stack)
Stack = 10
5 * 1 = 5 (push to stack)
Stack = 10 , 5
Seventh character : 5 (operand) (push to stack)
Stack = 10 , 5 , 5
Eighth character : - (operator) (pop top two operands, solve and push back to stack)
Stack = 10
5 - 5 = 0 (push to stack)
Stack = 10 , 0
Ninth character : + (operator) (pop top two operands, solve and push back to stack)
Stack = empty
10 + 0 = 10 (push to stack)
Stack = 10
So, the final answer is 10.