Change ( P + Q * ( R - S ) / T ) into postfix expression :-
Symbol Scanned
|
Operation
|
Stack
|
Expression
|
(
|
Push to Stack
|
(
|
|
P
|
Add to Expression
|
(
|
P
|
+
|
Push to Stack
|
( +
|
P
|
Q
|
Add to Expression
|
( +
|
P Q
|
*
|
Push to Stack
|
( + *
|
P Q
|
(
|
Push to Stack
|
( + * (
|
P Q
|
R
|
Add to Expression
|
( + * (
|
P Q R
|
-
|
Push to Stack
|
( + * ( -
|
P Q R
|
S
|
Add to Expression
|
( + * ( -
|
P Q R S
|
)
|
Pop ‘-‘
|
( + *
|
P Q R S -
|
/
|
Push to Stack
Pop ‘*’
|
( + /
|
P Q R S - *
|
T
|
Add to Expression
|
( + /
|
P Q R S - * T
|
)
|
Push to Stack
Pop ‘/’ and ‘+’
|
Empty
|
P Q R S - * T/ +
|
No comments:
Post a Comment