

Up:Assignment
2Previous:The
polynomial ADT(12 points)
Postfix, Infix and Prefix expressions(8
points)
Using the ADT Stack, perform the following operations:
-
Write a function to evaluate a postfix expression, e.g :
-
[ 12 4 - ] = 8
-
[ 12 13 + 4 1 - / ] = 8.33
-
[ 12 13 + 4 1 - sqrt / ] = 14.43
-
Write a function to convert a postfix expression to prefix, e.g.:
-
[ 12 13 + ]
[ + 12 13 ]
-
[ 12 13 + 4 1 - / ]
[ / + 12 13 - 4 1 ]
-
[ 12 13 + 4 1 - exp / ]
[ / + 12 13 exp - 4 1 ]
-
Write a function to convert a postfix expression to infix, e.g:
-
[ 12 13 + ]
[ (12 + 13) ]
-
[ 12 13 + 4 1 - / ]
[ ((12 + 13) / (4 - 1)) ]
-
[ 12 13 + 4 1 - sqrt / ]
[ ((12 + 13) / (sqrt (4 - 1))) ]
The arithmetic expression includes the arithmetic operators + , - , / ,
* , the unary functions sin, cos, tan, exp, log, sqrt and the round brackets
(,) in the case of question 3.
Malek Mouhoub
Friday February 4 19:04:44 MST 2000