Friday, 19 August 2016

Conversion of Infix expression to Postfix expression Example 3

Conversion of Infix expression to Postfix expression 

Example 3:


Given Infix Expression:         ( ( A – ( B + C ) ) * D ) $ ( E+ F )


Symbol
Operator Stack
Postfix String
[0]
[1]
[2]
[3]
[4]

1
(
(






2
(
(
(





3
A
(
(




A
4
-
(
(
-



A
5
(
(
(
-
(


A
6
B
(
(
-
(


AB
7
+
(
(
-
(
+

AB
8
C
(
(
-
(
+

ABC
9
)
(
(
-



ABC+
10
)
(





ABC+-
11
*
(
*




ABC+-
12
D
(
*




ABC+-D
13
)






ABC+-D*
14
$
$





ABC+-D*
15
(
$
(




ABC+-D*
16
E
$
(




ABC+-D*E
17
+
$
(
+



ABC+-D*E
18
F
$
(
+



ABC+-D*EF
19
)
$





ABC+-D*EF+
20


ABC+-D*EF+$




So the corresponding Postfix expression is ABC+-D*EF+$

No comments:

Post a Comment