Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
774 views
in Computer by (51.9k points)
closed by

Evaluation of Postfix Expression.

1 Answer

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

Stacks can be used to evaluate an expression in postfix notation. For simplification, we are assuming that operators used in expressions are binary operators. The detailed step by step procedure is given in Algorithm.

Algorithm: Evaluation of postfix expression

Step 1: INPUT postfix expression in a variable, say postExp 

Step 2: For each character in postExp, REPEAT Step 3 

Step 3: IF character is an operand 

              THEN PUSH character on the Stack 

                       ELSE POP two elements from the Stack, apply 

              the operator on the popped elements and PUSH the computed value onto 

              the Stack 

Step 4: IF Stack has a single element 

   THEN POP the element and OUTPUT as the net result 

   ELSE OUTPUT “Invaild Postfix expression”

Example

Figure shows the step-by-step process of evaluation of the postfix expression 7 8 2 * 4 / + using Algorithm.

Evaluation of postfix expression 7 8 2 * 4 /+

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

...