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

Write an algorithm to convert infix expression to postfix expression. 

1 Answer

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

1.  Push “(“ onto STACK, and add “)” to the end of X.

2.  Scan X from left to right and REPEAT Steps3 to 6 for each element of X UNTIL the STACK is empty.

3.  If an operand is encountered, add it to Y.

4.  If a left parenthesis is encountered, push it onto STACK.

5.  If an operator is encountered, then:

(a) Repeatedly pop from STACK and add to Y each operator (on the top of STACK) which has the same precedence as or higher precedence than operator.

(b) Add operator to STACK. 

/* End of If structure */

6.  If a right parenthesis is encountered, then:

(a) Repeatedly pop from STACK and add to Y each operator (on the top of STACK) until a left Parenthesis is encountered.

(b)  Remove the left parenthesis. (Do not add the left parenthesis to Y).

/* End of If structure */ 

7.  END.

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

...