[go: up one dir, main page]

0% found this document useful (0 votes)
124 views36 pages

DataStructure Infix, Postfix, Prefix Expression

Uploaded by

Sunil Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views36 pages

DataStructure Infix, Postfix, Prefix Expression

Uploaded by

Sunil Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Class-XII

Subject: Computer Science with Python


Chapter: Data Structure (Stack)

1. Infix Expression
Definition
An infix expression is a way of writing mathematical expressions where operators are placed between the operands.
This is the form we usually use in everyday mathematics.
• Example:
A+B
Here:
• A and B are operands (values or variables)
• + is the operator
• The operator is between operands → infix

More Examples:
1. A + B - C
2. (A + B) * C
3. (X * Y) + Z

Important Points:
• Infix expressions are easy for humans to read.
• Computers find them harder to evaluate directly because operator precedence and brackets must be considered.
• Example with precedence:
A + B * C means A + (B * C) (multiplication happens before addition).

2. Postfix Expression
Definition
A postfix expression (also called Reverse Polish Notation, RPN) is a way of writing mathematical expressions where the
operator comes after the operands.
• Example:
AB+
Here:
• A and B are operands
• + is the operator
• Operator comes after the operands → postfix

More Examples:
1. A B + C - → equivalent to (A + B) - C
2. A B C * + → equivalent to A + (B * C)
3. X Y * Z + → equivalent to (X * Y) + Z

Why Postfix is Useful in Computers:


• No need for brackets or parentheses.
• Operator precedence is handled automatically.
• Can be evaluated easily using a stack.

Example Conversion and Evaluation:


Infix → Postfix:
Infix: (A + B) * C
Postfix: A B + C *
Evaluating Postfix A B + C * when:
A = 2, B = 3, C = 4
Steps (using stack):

Step Symbol Action Stack

1 A=2 Push 2

2 B=3 Push 23

3 + Pop 3, Pop 2 → 2+3=5 5

4 C=4 Push 54

5 * Pop 4, Pop 5 → 5*4=20 20

Final Answer: 20
What is a Prefix Expression?
A prefix expression (also called Polish notation) is a way of writing mathematical expressions where the operator comes
before the operands.
• Form:
Operator Operand1 Operand2

Example
+AB
This means:
A+B

More Examples
Infix (Normal) Prefix (Operator First)

A+B +AB

(A + B) * C * +AB C

(X * Y) + Z +*XYZ

A–B+C + -AB C
Key Points
• No parentheses are needed in prefix notation because the position of the operator tells us the order of evaluation.
• Operator precedence and associativity are handled naturally by the notation.
• Prefix expressions are evaluated from right to left (unlike postfix which is left to right).
• Can be easily converted from infix using a stack.

Infix → Prefix Conversion Algorithm (Stack Method)


Steps:
1. Reverse the infix expression.
o While reversing, swap ( ) → ( becomes ) and ) becomes (.
2. Convert the reversed expression to postfix (using the standard infix-to-postfix algorithm).
3. Reverse the postfix result — the final result is prefix.

Example Conversion
Infix:
(A + B) * C
Step 1: Reverse and swap brackets:
C * (B + A)
Step 2: Convert to postfix:
C BA+ *
Step 3: Reverse postfix:
* +AB C
Prefix:
* +AB C

Prefix Evaluation (Right-to-Left)


Example:
Prefix:
+*234
Meaning:
(2 * 3) + 4
Steps (using stack):

Step Scan Action Stack

1 4 Push operand 4

2 3 Push operand 43

3 2 Push operand 432

4 * Pop 2, Pop 3 → multiply → Push result 6 46

5 + Pop 6, Pop 4 → add → Push result 10 10

Answer: 10
Board-style Example: Infix → Prefix
Infix:
A / B + C * (D – E)
Step 1: Reverse & swap brackets:
(E –D )* C+B/A
Step 2: Convert to postfix:
E D - C* BA/ +
Step 3: Reverse postfix:
+/AB* C-ED
Prefix:
+/AB* C-ED
Question1: Transform the following expression to both prefix and postfix form:
(A + B * C – D) / E * F

Step 1 – Understand Operator Precedence


Order of precedence:
1. * and / → higher (evaluated before + and -)
2. + and - → lower (evaluated left to right)
Expression grouping:
((A + (B * C)) – D) / E * F

Step 2 – Convert to Postfix


We convert infix → postfix using stack rules or directly from grouping.
1. B * C → B C *
2. A + (B C *) → A B C * +
3. (A B C * +) – D → A B C * + D -
4. Divide by E → A B C * + D - E /
5. Multiply by F → A B C * + D - E / F *
Postfix:
ABC*+D-E/F*
Step 3 – Convert to Prefix
We convert infix → prefix using precedence or by the reverse-bracket method.
1. B * C → * B C
2. A + (* B C) → + A * B C
3. (+ A * B C) – D → - + A * B C D
4. Divide by E → / - + A * B C D E
5. Multiply by F → * / - + A * B C D E F
Prefix:
* / - +A* B C D E F

Final Answer Table

Notation Expression

Prefix * / - +A* B C D E F

Postfix ABC*+D-E/F*
Q2. Transform the following expressions to infix form:
1. + - ABC
2. + A – BC
Solution: We’ll convert prefix → infix using the standard stack method:
Method (right-to-left):
Scan from right to left.
• If token is an operand, push it.
• If token is an operator, pop two items → left then right, form (left op right), and push back.

1) Prefix: + - A B C

Step Token Action Stack (bottom → top)

1 C Push operand C

2 B Push operand C, B

3 A Push operand C, B, A

4 − Pop A (left), B (right) → form (A − B) → push C, (A − B)

5 + Pop (A − B) (left), C (right) → form ((A − B) + C) → push ((A − B) + C)

Infix result:
(A − B) + C
2) Prefix: + A − B C

Step Token Action Stack (bottom → top)

1 C Push operand C

2 B Push operand C, B

3 − Pop B (left), C (right) → form (B − C) → push (B − C)

4 A Push operand (B − C), A

5 + Pop A (left), (B − C) (right) → form (A + (B − C)) → push (A + (B − C))

Infix result:
A + (B − C)
Q3. Evaluate the following postfix expression using a stack and show the contents of the stack after execution of each
operation 5, 6, 9, +, 80, 5, *, -, /
Solution: Postfix Expression
5 6 9 + 80 5 * - /

Step-by-Step Table (Exact Fractions)

Step Symbol Action Stack after step

1 5 Push operand 5

2 6 Push operand 5, 6

3 9 Push operand 5, 6, 9

4 + Pop 9, Pop 6 → 6 + 9 = 15 → Push 5, 15

5 80 Push operand 5, 15, 80

6 5 Push operand 5, 15, 80, 5

7 * Pop 5, Pop 80 → 80 × 5 = 400 → Push 5, 15, 400

8 - Pop 400, Pop 15 → 15 − 400 = -385 → Push 5, -385

9 / Pop -385, Pop 5 → 5 ÷ (-385) = -5/385 → simplify → -1/77 -1/77


Q1) Convert to postfix
Infix: U * V + R / (S – T)

Step Symbol Action Stack Postfix (Y)

1 U Output operand U

2 * Push * * U

3 V Output operand * UV

4 + Pop * (higher/equal) → output, then push + + UV*

5 R Output operand + UV*R

6 / Push / (higher than +) +/ UV*R

7 ( Push ( +/( UV*R

8 S Output operand +/( UV*RS

9 – Push – +/( -

10 T Output operand +/( -

11 ) Pop until ( → output –; discard ( +/ UV*RST-

12 ⏹ End: pop remaining → /, then + UV*RST-/+

Postfix: U V * R S T - / +
Q2) Convert to postfix
Infix: P / (Q – R) * S + T

Step Symbol Action Stack Postfix (Y)

1 P Output operand P

2 / Push / / P

3 ( Push ( /( P

4 Q Output operand /( PQ

5 – Push – / (- PQ

6 R Output operand / (- PQR

7 ) Pop until ( → output –; discard ( / PQR-

8 * * vs /: pop / (equal precedence) → output, then push * * PQR-/

9 S Output operand * PQR-/S

10 + Pop * → output, then push + + PQR-/S*

11 T Output operand + PQR-/S*T

12 ⏹ End: pop + PQR-/S*T+

Postfix: P Q R - / S * T +
Q3) Convert to postfix
Infix: X / Y + U * (V – W)

Step Symbol Action Stack Postfix (Y)

1 X Output operand X

2 / Push / / X

3 Y Output operand / XY

4 + Pop / → output, then push + + XY/

5 U Output operand + XY/U

6 * Push * (higher than +) +* XY/U

7 ( Push ( +*( XY/U

8 V Output operand +*( XY/UV

9 – Push – + * (- XY/UV

10 W Output operand + * (- XY/UVW

11 ) Pop until ( → output –; discard ( +* XY/UVW-

12 ⏹ End: pop *, then + XY/UVW-*+

Postfix: X Y / U V W - * +
Q4) Convert to postfix
Infix: P / (Q + (R – T) * U)

Step Symbol Action Stack Postfix (Y)

1 P Output operand P

2 / Push / / P

3 ( Push ( /( P

4 Q Output operand /( PQ

5 + Push + / (+ PQ

6 ( Push ( / (+ ( PQ

7 R Output operand / (+ ( PQR

8 – Push – / (+ (- PQR

9 T Output operand / (+ (- PQRT

10 ) Pop until ( → output –; discard ( / (+ PQRT-

11 * Push * (higher than +) / (+ * PQRT-

12 U Output operand / (+ * PQRT-U

13 ) Pop until ( → pop * then +; discard ( / PQRT-U*+

14 ⏹ End: pop / PQRT-U*+/

Postfix: P Q R T - U * + /
Q5) Convert to postfix
Infix: X – Y / (Z + U) * V

Step Symbol Action Stack Postfix (Y)

1 X Output operand X

2 – Push – – X

3 Y Output operand – XY

4 / Push / (higher than –) –/ XY

5 ( Push ( –/( XY

6 Z Output operand –/( XYZ

7 + Push + – / (+ XYZ

8 U Output operand – / (+ XYZU

9 ) Pop until ( → output +; discard ( –/ XYZU+

10 * * vs /: pop / (equal) → output, then push * –* XYZU+/

11 V Output operand –* XYZU+/V

12 ⏹ End: pop *, then – XYZU+/V*-

Postfix: X Y Z U + / V * -
Q6) Convert to postfix
Infix: A / B + C * (D – E)

Step Symbol Action Stack Postfix (Y)

1 A Output operand A

2 / Push / / A

3 B Output operand / AB

4 + Pop / → output; push + + AB/

5 C Output operand + AB/C

6 * Push * (higher than +) +* AB/C

7 ( Push ( +*( AB/C

8 D Output operand +*( AB/CD

9 – Push – + * (- AB/CD

10 E Output operand + * (- AB/CDE

11 ) Pop until ( → output –; discard ( +* AB/CDE-

12 ⏹ End: pop *, then + AB/CDE-*+

Postfix: A B / C D E - * +
Converting Infix to Postfix
Infix: Operators are between operands.
Example: A + B
Postfix: Operators come after operands.
Example: A B +

Algorithm (Infix → Postfix)


We usually use a stack for operators.
Steps:
1. Read the infix expression from left to right.
2. Operands (A, B, numbers, etc.) → Add directly to output (postfix).
3. *Operators (+, -, , /, ^) →
o Pop operators from the stack with higher or equal precedence and add to output before pushing the current
operator.
o Then push the current operator onto the stack.
4. Left parenthesis '(' → Push onto the stack.
5. Right parenthesis ')' → Pop from the stack and add to output until '(' is found. Remove '(' from the stack.
6. End of expression → Pop and add all remaining operators from the stack to output.
Example 1: (A + B) * C
Step-by-step:
1. ( → Push to stack. Stack: (, Output: –
2. A → Operand → Output: A
3. + → Push to stack. Stack: ( +, Output: A
4. B → Operand → Output: A B
5. ) → Pop until (. Output: A B +, Stack: –
6. * → Push to stack. Stack: *, Output: A B +
7. C → Operand → Output: A B + C
8. End → Pop * → Output: A B + C *
Final Postfix:
AB+C*
Example 2: A + B * C - D
1. A → Output: A
2. + → Push. Stack: +
3. B → Output: A B
4. * → Higher precedence than + → Push. Stack: + *
5. C → Output: A B C
6. End of B*C → Pop * → Output: A B C *
7. + still in stack → Output: A B C * +
8. - → Equal precedence to +, pop + first → Output: A B C * +, Stack empty → Push -
9. D → Output: A B C * + D
10.End → Pop - → Output: A B C * + D -
Final Postfix:
ABC*+D-
Converting Postfix to Infix
Here we use a stack for operands.
Steps:
1. Read postfix from left to right.
2. Operand → Push onto stack.
3. Operator → Pop the top two elements from stack, say op2 (top) and op1 (next).
o Create a new string: (op1 operator op2)
o Push this back onto the stack.
4. End → The only element left in the stack is the final infix expression.

Example 1: A B + C *
1. A → Push: A
2. B → Push: A B
3. + → Pop B, A → (A + B) → Push: (A + B)
4. C → Push: (A + B) C
5. * → Pop C, (A + B) → ((A + B) * C) → Push.
6. End → Final: ((A + B) * C)
Example 2: A B C * + D -
1. A → Push: A
2. B → Push: A B
3. C → Push: A B C
4. * → Pop C, B → (B * C) → Push: A (B * C)
5. + → Pop (B * C), A → (A + (B * C)) → Push.
6. D → Push: (A + (B * C)) D
7. - → Pop D, (A + (B * C)) → ((A + (B * C)) - D) → Push.
8. End → Final: ((A + (B * C)) - D)

Quick Summary Table

Direction Key Data Structure Rule

Infix → Postfix Stack for operators Push operands to output, manage operator precedence, use parentheses rules

Postfix → Infix Stack for operands Push operands, when operator appears pop two operands and form (op1 operator op2)

Infix → Postfix
Algorithm Table
Step
Rule / Action
No.

1 Read the infix expression from left to right.


Step
Rule / Action
No.

2 If the symbol is an operand → Add to output (postfix).

If the symbol is an operator → Pop operators from stack with higher or equal precedence and add to output, then
3
push the current operator.

4 If symbol is '(' → Push to stack.

5 If symbol is ')' → Pop from stack to output until '(' is found; remove '('.

6 After reading all symbols → Pop all remaining operators to output.

Example Table – (A + B) * C

Step Symbol Scanned Action Stack Output (Postfix)

1 ( Push ( –

2 A Operand → Output ( A

3 + Push (+ A

4 B Operand → Output (+ AB

5 ) Pop until ( – AB+

6 * Push * AB+

7 C Operand → Output * AB+C

8 End Pop all operators – AB+C*

Final Postfix: A B + C *
Postfix → Infix
Algorithm Table
Step No. Rule / Action

1 Read the postfix expression from left to right.

2 If the symbol is an operand → Push onto operand stack.

3 If the symbol is an operator → Pop top two operands → Form (op1 operator op2) → Push result back onto stack.

4 After reading all symbols → The stack will contain the final infix expression.

Example Table – A B + C *

Symbol
Step Action Stack Output (Infix)
Scanned

1 A Operand → Push A –

2 B Operand → Push AB –

3 + Pop B, A → (A + B) → Push (A + B) (A + B)

4 C Operand → Push (A + B) C (A + B)

Pop C, (A + B) → ((A + B) * C)
5 * ((A + B) * C) ((A + B) * C)
→ Push

6 End Final expression is on stack ((A + B) * C) –

Final Infix: ((A + B) * C)


Q1. Infix → Postfix → Stepwise Evaluation with Expression (Y)
a) (A + B – C * D)
Postfix: A B + C D * –
Step Symbol Scanned Action Stack Output (Expression Y)

1 A Push A A –

2 B Push B AB –

3 + Pop B, Pop A → (A + B) (A + B) (A + B)

4 C Push C (A + B) C (A + B)

5 D Push D (A + B) C D (A + B)

6 * Pop D, Pop C → (C * D) (A + B) (C * D) (C * D)

7 – Pop (C * D), Pop (A + B) → (A + B – C * D) (A + B – C * D) (A + B – C * D)


Final Answer: A + B – C × D
b) (A * ((C + D) / E))
Postfix: A C D + E / *
Step Symbol Scanned Action Stack Output (Expression Y)

1 A Push A A –

2 C Push C AC –

3 D Push D ACD –

4 + Pop D, Pop C → (C + D) A (C + D) (C + D)

5 E Push E A (C + D) E (C + D)

6 / Pop E, Pop (C + D) → ((C + D) / E) A ((C + D) / E) ((C + D) / E)

7 * Pop ((C + D) / E), Pop A → (A * ((C + D) / E)) (A * ((C + D) / E)) (A * ((C + D) / E))

Final Answer: A × ((C + D) ÷ E)


Q2. Evaluate postfix with A=3, B=5, C=1, D=4
a) A B + C * → 3 5 + 1 *
Step Symbol Scanned Action Stack Output (Expression Y)

1 3 Push 3 3 –

2 5 Push 5 35 –

3 + Pop 5, 3 → 3 + 5 = 8; push 8 8 3+5=8

4 1 Push 1 81 3+5=8

5 * Pop 1, 8 → 8 × 1 = 8; push 8 8 8×1=8

Final Answer: 8
b) A B * C / D * → 3 5 * 1 / 4 *
Step Symbol Scanned Action Stack Output (Expression Y)

1 3 Push 3 3 –

2 5 Push 5 35 –

3 * Pop 5, 3 → 3 × 5 = 15; push 15 15 3 × 5 = 15

4 1 Push 1 15 1 3 × 5 = 15

5 / Pop 1, 15 → 15 ÷ 1 = 15; push 15 15 15 ÷ 1 = 15

6 4 Push 4 15 4 15 ÷ 1 = 15

7 * Pop 4, 15 → 15 × 4 = 60; push 60 60 15 × 4 = 60


Q1(c)
Infix Expression:
(A+B)∗(C−D/E)+(F∗(G+H))
(Here we have 14 symbols: A,B,+,C,D,/,E,-,,F,G,H,+,,+)
Postfix Conversion:
AB+CDE/-*FGH+*+
Step-by-Step Table:

Symbol
Step Action Stack Output (Expression Y)
Scanned

1 A Push A A –

2 B Push B AB –

3 + Pop B, A → (A + B) (A + B) (A + B)

4 C Push C (A + B) C (A + B)

5 D Push D (A + B) C D (A + B)

6 E Push E (A + B) C D E (A + B)

7 / Pop E, D → (D / E) (A + B) C (D / E) (D / E)

8 - Pop (D / E), C → (C - (D / E)) (A + B) (C - D / E) (C - D / E)

Pop (C - D / E), (A + B) → ((A + B) *


9 * ((A + B) * (C - D / E)) ((A + B) * (C - D / E))
(C - D / E))
Symbol
Step Action Stack Output (Expression Y)
Scanned

10 F Push F ((A + B) * (C - D / E)) F ((A + B) * (C - D / E))

((A + B) * (C - D / E)) F
11 G Push G ((A + B) * (C - D / E))
G

((A + B) * (C - D / E)) F
12 H Push H ((A + B) * (C - D / E))
GH

((A + B) * (C - D / E)) F
13 + Pop H, G → (G + H) (G + H)
(G + H)

((A + B) * (C - D / E)) (F
14 * Pop (G + H), F → (F * (G + H)) (F * (G + H))
* (G + H))

Pop (F * (G + H)), ((A + B) * (C - D /


((A + B) * (C - D / E) + ((A + B) * (C - D / E) + (F * (G
15 + E)) → ((A + B) * (C - D / E) + (F * (G
(F * (G + H))) + H)))
+ H)))

Final Answer: (A+B)×(C−D/E)+(F×(G+H))


Q1(d)
Infix Expression:
((A+B−C)∗(D+E/F))−((G∗H)+(I/(J−K)))
(Here we have 16 symbols: A,B,+,C,-,D,E,F,/,+,,G,H,,I,J,K,-,/,+,-)
Postfix Conversion:
AB+C-DEF/+*GH*IJK-/+-
Step-by-Step Table:

Symbol
Step Action Stack Output (Expression Y)
Scanned

1 A Push A A –

2 B Push B AB –

3 + Pop B, A → (A + B) (A + B) (A + B)

4 C Push C (A + B) C (A + B)

5 - Pop C, (A + B) → ((A + B) - C) ((A + B) - C) ((A + B) - C)

6 D Push D ((A + B) - C) D ((A + B) - C)

7 E Push E ((A + B) - C) D E ((A + B) - C)

8 F Push F ((A + B) - C) D E F ((A + B) - C)

9 / Pop F, E → (E / F) ((A + B) - C) D (E / F) (E / F)

10 + Pop (E / F), D → (D + (E / F)) ((A + B) - C) (D + E / F) (D + E / F)


Symbol
Step Action Stack Output (Expression Y)
Scanned

Pop (D + E / F), ((A + B) - C) → (((A + B)


11 * (((A + B) - C) * (D + E / F)) (((A + B) - C) * (D + E / F))
- C) * (D + E / F))

(((A + B) - C) * (D + E / F))
12 G Push G (((A + B) - C) * (D + E / F))
G

(((A + B) - C) * (D + E / F))
13 H Push H (((A + B) - C) * (D + E / F))
GH

(((A + B) - C) * (D + E / F))
14 * Pop H, G → (G * H) (G * H)
(G * H)

(((A + B) - C) * (D + E / F))
15 I Push I (((A + B) - C) * (D + E / F))
(G * H) I

(((A + B) - C) * (D + E / F))
16 J Push J (((A + B) - C) * (D + E / F))
(G * H) I J

(((A + B) - C) * (D + E / F))
17 K Push K (((A + B) - C) * (D + E / F))
(G * H) I J K

(((A + B) - C) * (D + E / F))
18 - Pop K, J → (J - K) (J - K)
(G * H) I (J - K)

(((A + B) - C) * (D + E / F))
19 / Pop (J - K), I → (I / (J - K)) (I / (J - K))
(G * H) (I / (J - K))

Pop (I / (J - K)), (G * H) → ((G * H) + (I / (((A + B) - C) * (D + E / F))


20 + ((G * H) + (I / (J - K)))
(J - K))) ((G * H) + (I / (J - K)))

21 - Pop ((G * H) + (I / (J - K))), (((A + B) - C) ((((A + B) - C) * (D + E / ((((A + B) - C) * (D + E / F)) -


Symbol
Step Action Stack Output (Expression Y)
Scanned

* (D + E / F)) → ((((A + B) - C) * (D + E / F)) - ((G * H) + (I / (J - ((G * H) + (I / (J - K))))


F)) - ((G * H) + (I / (J - K)))) K))))

Final Answer:
(((A+B)−C)×(D+E/F))−((G×H)+(I/(J−K)))

Example 1 (Small)
Postfix Expression:
AB+CD*-
Step-by-Step Table:

Step Symbol Scanned Action Stack Output (Expression Y)

1 A Push A A –

2 B Push B AB –

3 + Pop B, A → (A + B) (A + B) (A + B)

4 C Push C (A + B) C (A + B)

5 D Push D (A + B) C D (A + B)

6 * Pop D, C → (C * D) (A + B) (C * D) (C * D)

7 - Pop (C * D), (A + B) → ((A + B) - (C * D)) ((A + B) - (C * D)) ((A + B) - (C * D))

Final Infix:
(A+B)−(C×D)
Example 2 (Bigger – 12 symbols)
Postfix Expression:
AB+CDE/-*FGH+*+
(This is actually the Postfix form of the earlier Q1(c) big expression.)
Step-by-Step Table:

Symbol
Step Action Stack Output (Expression Y)
Scanned

1 A Push A A –

2 B Push B AB –

3 + Pop B, A → (A + B) (A + B) (A + B)

4 C Push C (A + B) C (A + B)

5 D Push D (A + B) C D (A + B)

6 E Push E (A + B) C D E (A + B)

7 / Pop E, D → (D / E) (A + B) C (D / E) (D / E)

8 - Pop (D / E), C → (C - (D / E)) (A + B) (C - (D / E)) (C - (D / E))

Pop (C - (D / E)), (A + B) → ((A + B) * (C - (D /


9 * ((A + B) * (C - (D / E))) ((A + B) * (C - (D / E)))
E)))

((A + B) * (C - (D / E)))
10 F Push F ((A + B) * (C - (D / E)))
F
Symbol
Step Action Stack Output (Expression Y)
Scanned

((A + B) * (C - (D / E)))
11 G Push G ((A + B) * (C - (D / E)))
FG

((A + B) * (C - (D / E)))
12 H Push H ((A + B) * (C - (D / E)))
FGH

((A + B) * (C - (D / E)))
13 + Pop H, G → (G + H) (G + H)
F (G + H)

((A + B) * (C - (D / E)))
14 * Pop (G + H), F → (F * (G + H)) (F * (G + H))
(F * (G + H))

Pop (F * (G + H)), ((A + B) * (C - (D / E))) → (((A + B) * (C - (D / (((A + B) * (C - (D / E))) +


15 +
(((A + B) * (C - (D / E))) + (F * (G + H))) E))) + (F * (G + H))) (F * (G + H)))

Final Infix:
((A+B)×(C−(D/E)))+(F×(G+H))

You might also like