Docsity

Example of postfix using infix to postfix, Summaries of Engineering

Partial preview of the text

Download Example of postfix using infix to postfix and more Summaries Engineering in PDF only on Docsity!

(A*B)DYEAESG'D}C Initial State == mpty (AsB)'D+E/(FHG"D)+C ( Push ( ( 4B)" D+E(E+G*D)+C A Print A ( + Push + (+ Input: —Infix String= A-(B+C/D-(E+F*G)-H) Output Step Postfix String Get A A Push - A Push ( A Get B AB Push + AB Get C ABC Push / ABC Get D ABCD Pop / ABCD/ Pop + ABCD/+ Push - ABCD/+ Push ( ABCD/+ Get E ABCD/+E Push+ ABCD/+E Get F ABCD/+EF Push * ABCD/+EF Get G ABCD/+EFG Pop * ABCD/+EFG* Pop + ABCD/+EFG*+ Pop - ABCD/+EFG*+- Push - ABCD/+EFG*+- Get H ABCD/+EFG*+-H Pop - ABCD/+EFG*+-H- Pop - ABCD/+EFG*+-H— Finish ABCD/+EFG*+-H— Postfix Expression : 20 5036 +* * 300/2- Token Action Stack 2 Push 20 to stack [20] 5 Push 50 to stack (20, 50] 3 Push 3 to stack [20, 50, 3] 6 Push 6 to stack [20, 50, 3, 6] Pop 6 from stack [20, 50, 3] + Pop 3 from stack (20, 50} Push 3+6 =9 to stack [20, 50, 9] Pop 9 from stack [20, 50] * Pop 50 from stack [20] Push 50*9=450 to stack [20, 450] Pop 450 from stack [20] * Pop 20 from stack it} Push 20*450=9000 to stack [9000] 300 Push 300 to stack [9000, 300] Pop 300 from stack [9000] / Pop 9000 from stack it} Push 9000/300=30 to stack [30] 2 Push 2 to stack [30, 2] Pop 2 from stack [30] - Pop 30 from stack it} Push 30-2=28 to stack [28] Result : 28 Infix Stack Postfix 8*(3+4y/2-3*5 # *(3+4)/2-3*5 # 8 (3+4)/2-3*5 #* 8 3+4y2-3*5 #*( 8 +4y2-3*5 #*( 83 4y2-3*S a(t 83 y2-3*5 #*(+ 834 /2-3°5 # 834+ 2-35 #/ 834+" 345 #/ 834+*2 595 ae 834+*2/ ax | Be 834+*2/3 5 a* 834+*2/3 #* 834+*2/35 #- 834+*2/35* & 834+*2/35*- Figure 7: Table of converting infix to postfix Postfix Character | Operator | Operand 1 | Operand2 | Result | Stack wa 2as* 3 3 34+92/35*- 3 83 4492/35*- 4 834 +*2/35°- + + a 3 ey 87 #2/35°- . . 7 8 36 | 56 235*- 2 562 135% / / 2 56 28 | 28 35%. 3 283 s*- 5 2835 * . . 5 3 1s | 2815 : “ : 1s 28 13/13