nextupprevious
Up:Assignment 2Previous:The polynomial ADT(12 points)

Postfix, Infix and Prefix expressions(8 points)

Using the ADT Stack, perform the following operations:
  1. Write a function to evaluate a postfix expression, e.g :
  2. [ 12 4 - ] = 8
    [ 12 13 + 4 1 - / ] = 8.33
    [ 12 13 + 4 1 - sqrt / ] = 14.43

     

     
     
     

  3. Write a function to convert a postfix expression to prefix, e.g.:
  4. [ 12 13 + ] tex2html_wrap_inline115 [ + 12 13 ]
    [ 12 13 + 4 1 - / ] tex2html_wrap_inline115 [ / + 12 13 - 4 1 ]
    [ 12 13 + 4 1 - exp / ] tex2html_wrap_inline115 [ / + 12 13 exp - 4 1 ]

     

     
     
     

  5. Write a function to convert a postfix expression to infix, e.g:
  6. [ 12 13 + ] tex2html_wrap_inline115 [ (12 + 13) ]
    [ 12 13 + 4 1 - / ] tex2html_wrap_inline115 [ ((12 + 13) / (4 - 1)) ]
    [ 12 13 + 4 1 - sqrt / ] tex2html_wrap_inline115 [ ((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