Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
5.5k views
in Computer by (61.3k points)
edited by

Use a stack to evaluate the following postfix expression and show the content of the stack after execution of each operation. Don’t write any code. Assume as if you are using push and pop member functions of the stack AB- CD+E*+

(where A=5, B=3, C=5, D=4, and E=2)

1 Answer

+1 vote
by (64.1k points)
selected by
 
Best answer

Expression is 5, 3, -, 5, 4, +, 2, *, +


SNo.
Symbol Action taken  Stack intermediate output
1 5  operand, push 5
2 3  operand, push 5,3
3 - operator, pop twice 5-3=2
Evaluate and push back 2
4 5 operand, push 2,5
5 4  operand, push 2,5,4
6 + operator, pop twice 2 5+4=9
Evaluate and push back 2,9
7 2 operand, push 2,9,2
8 * operator, pop twice 2 9*2=18
Evaluate and push back 2,18
9 + operator, pop twice 2+18=20
Evaluate and push back 20
10 pop all 20

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...