Search code examples
pythonpostfix-operatorprefix-operator

Learning Postfix


While I was going through the postfix at this site I'm just confused as after the definition of infix prefix and postfox it explains its rule that how to apply postfix, as it completely says: Prefix expression notation requires that all operators precede the two operands that they work on. Postfix, on the other hand, requires that its operators come after the corresponding operands.

Examples:

A + B * C = Normal used(Infix)

A + B * C = Now if we want to convert this into prefix we have to move all operator just before the two operands they work on. i.e + will come before A and * will come before B. Ok so far so good.
+ A * B C = Prefix

A + B * C = Now if we want to convert this into postfix we have to move operator just after the two operands they work on i.e + should come after B and * will come after C. According to the rule it should be like this: A B + C * but in the example it shows us this:
A B C * + = Postfix.

Please explain me where I'm going wrong.

Thanks in advance

--
Regards
Pradeep


Solution

  • You need to read it in the order they will be applied. First * will be applied to B and C; then + will be applied to the result of that calculation and A. So, the site is correct.

    Note, this has nothing to do with Python, which does not support postfix notation.