6 Conversion of An Infix Expression To The Postfix

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Conversion of an infix expression to the postfix

I1: A+B*(C-D)/E-F*G-(H*I)^J/K
Step 1: A+B*(C-D)/E-F*G-(H*I)^J/K )
Step 2: ( ADD ON STACK
Step 3: Symbols Scanning

Symbol Scanned Stack Postfix Expression (P1)


(
A ( A
+ (+ A
B (+ AB
* (+* AB
( (+*( AB
C (+*( ABC
- (+*(- ABC
D (+*(- ABCD
) (+* ABCD-
/ (+/ ABCD-*
E (+/ ABCD-*E
- (- ABCD-*E/+
F (- ABCD-*E/+F
* (-* ABCD-*E/+F
G (-* ABCD-*E/+FG
- (- ABCD-*E/+FG*-
( (-( ABCD-*E/+FG*-
H (-( ABCD-*E/+FG*-H
* (-(* ABCD-*E/+FG*-H
I (-(* ABCD-*E/+FG*-HI
) (- ABCD-*E/+FG*-HI*
^ (-^ ABCD-*E/+FG*-HI*
J (-^ ABCD-*E/+FG*-HI*J
/ (-/ ABCD-*E/+FG*-HI*J^
K (-/ ABCD-*E/+FG*-HI*J^K
) ABCD-*E/+FG*-HI*J^K/-
Evaluation of postfix expression
P: 9 3 4 * 8 + 4 / -
P: 9 3 4 * 8 + 4 / - )
A=5
B=9
C= B (OPERATOR) A
C=9-5
C=4

Symbol Scan Stack


9 9
3 9,3
4 9,3,4
* 9 , 12
8 9 , 12, 8
+ 9 , 20
4 9 , 20, 4
/ 9,5
- 4
)

You might also like