Infix to Prefix
1. If E is a variable or constant then Prefix(E) = E
2. if E is E1 op E2 then Prefix(E) = Prefix(E1 op E2) = op Prefix(E1) Prefix(E2)
3. If E is (E1) then Prefix(E) = Prefix(E1)
Example:
Prefix( A * B + C / D )
= Prefix ( ( A * B ) + ( C / D ) )
= + Prefix( A * B) Prefix( C / D )
= + * Prefix( A ) Prefix( B ) / Prefix ( C ) Prefix( D )
= + * A B / C D
Postfix to Infix
1. If E is a variable or constant then Infix(E) = E
2. if E is E1 E2 op then Infix(E) = Infix(E1 E2 op) = Infix(E1) op Infix(E2)
3. If E is (E1) then Infix(E) = Infix(E1)
Example:
Infix( A B * C D / + )
= Infix( ( A B * ) ( C D / ) + )
= Infix( A B * ) + Infix( C D / )
= Infix( A ) * Infix( B ) + Infix( C ) / Infix( D )
= A * B + C / D
Postfix to Prefix
1. If E is a variable or constant then Prefix(E) = E
2. if E is E1 E2 op then Prefix(E) = Prefix(E1 E2 op) = op Prefix(E1) Prefix(E2)
3. If E is (E1) then Prefix(E) = Prefix(E1)
Example:
Prefix( A B * C D / + )
= Prefix ( ( A B * ) ( C D /) + )
= + Prefix( A B * ) Prefix( C D /)
= + * Prefix( A ) Prefix( B ) / Prefix( C ) Prefix( D )
= + * A B / C D
Tuesday, July 29, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment