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
7.1k views
in Computer by (61.3k points)

Let P be the postfix arithmetic expression: 7, 2, -, 1, 14, -, 1, 2, * Evaluate P using stack and showing the status of the stack at every step.

1 Answer

+1 vote
by (64.2k points)
selected by
 
Best answer
SNo. Symbol Action taken Stack intermediate outpt
1 7 operand, push 7
2 2 operand, push 7, 2
3 - operator, pop twice 7-2=5
Evaluate and push back 5
4 1 operand, push 5, 1
5 14 operand, push 5, 1, 14
6 - operator, pop twice 5 1-14=-13
Evaluate and push back 5, -13
7 1 operand, push 5, -13, 1 1*2=2
8 2 operand, push 5, -13, 1, 2
9 * operator, pop twice  5, -13
Evaluate and push back 5, -13, 2

As 2 is the Top most value so answer should be 2.

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

...