Search code examples
data-structuresinfix-notationpostfix-notation

Evaluate Post order expression


What will be the resulted value of 7 4 3 + - 3 9 2 / + * 2 ^ 5 *

It is in post order. So how can I get the value of this expression?


Solution

  • Evaluate from right side. If it is operator than it is intermediate node. otherwise, it is leaf.

    So, "" is root of all. "5" is leaf on right side. Than start "^" as other intermediate node. "2" is right leaf. "" is left intermediate node. and so on.

    So final equation will be

    (((7(43+)-)(3(92/)+)*)2^)5* => (((7-(4+3)) * (3+(9/2)))^2) * 5 = 0