0% found this document useful (0 votes)
4 views5 pages

Infix to Postfix Conversion Guide

The document explains the conversion of Infix notation to Postfix notation and the evaluation of Postfix expressions using a stack. It provides a detailed example with the infix expression (A+B)*C, showing the conversion to Postfix (AB+C*) and the evaluation resulting in 20. Additionally, it outlines rules for operator precedence during the conversion process with further examples.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Infix to Postfix Conversion Guide

The document explains the conversion of Infix notation to Postfix notation and the evaluation of Postfix expressions using a stack. It provides a detailed example with the infix expression (A+B)*C, showing the conversion to Postfix (AB+C*) and the evaluation resulting in 20. Additionally, it outlines rules for operator precedence during the conversion process with further examples.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

While conversion of an Infix notation to its equivalent Prefix/Postfix notation,

only operators are Pushed onto the Stack.

When evaluating any Postfix expression using Stack, only operands are
PUSHed onto it.
Good Example

We’ll take this infix expression:

(A+B)∗C(A + B) * C(A+B)∗C

and assume values: A = 2, B = 3, C = 4.

1️⃣ Infix Expression

(A + B) * C

2️⃣ Convert Infix → Postfix

 Scan ( → push

 Scan A → operand → postfix = A

 Scan + → push

 Scan B → operand → postfix = AB


 Scan ) → pop till ( → postfix = AB+

 Scan * → push

 Scan C → operand → postfix = AB+C

 End of input → pop stack → postfix = AB+C*

✅ Postfix Expression = AB+C*

3️⃣ Evaluate Postfix (AB+C*)

Stack = [ ]

 Read A=2 → push → [2]

 Read B=3 → push → [2, 3]

 Read + → pop(3, 2) → 2+3=5 → push → [5]

 Read C=4 → push → [5, 4]

 Read * → pop(4, 5) → 5*4=20 → push → [20]

✅ Final Result = 20

🔑 Summary

 Infix: (A + B) * C

 Postfix: AB+C*

 Evaluation Result (A=2, B=3, C=4): 20

Important Rule

A+B*C

Step by step:

A → operand → goes directly to postExp → A


+ → operator → stack is empty, so push + → stack = [+]

B → operand → goes directly to postExp → AB

* → operator → compare with top of stack (+)

Precedence(*) > Precedence(+)

So we push * → stack = [+, *]

C → operand → goes to postExp → ABC

End of input → pop remaining stack → ABC*+

✅ Final postfix:

Copy code

ABC*+

Another Example (where popping happens)

Infix expression:

css

Copy code

A*B+C

A→A

* → push → stack = [*]


B → AB

+ → compare with * on top

Precedence(+) < Precedence(*)

So pop * → AB*

Now stack empty → push + → stack = [+]

C → AB*C

End → pop stack → AB*C+

✅ Final postfix:

mathematica

Copy code

AB*C+

You might also like