Algorithm to evaluate prefix expression?

前端 未结 2 463
夕颜
夕颜 2021-01-16 23:30

I have a prefix expression that only has the 4 binary operators(+,-,*,/) .A straight forward way to evaluate such an expression is to convert it to a postfix expression and

2条回答
  •  误落风尘
    2021-01-17 00:14

    Use a stack. Place your vars and operators and start popping each stack, one for operators and the other for varaiablss (the number of pops depending on arity).

提交回复
热议问题