Postfix Calculator is a computer program written in c++ codes that computes arithmetic expressions using the postorder algorithm.

example:

problem 1:

compute for the value of this binary tree using postorder algorithm. solution:

the written expression will be: 8 10 * 3 7 + /

(why??

In postorder algorithm, we will just write the value of the node when it will be the  last time that we will pass the node. The path will be from root node down to the  leaf node, from left to right as shown above. The curved arrow will be your path. )

the problem will be solved in this manner when postorder algorithm is used:

(8*10) / (3+7)  //which is equal to 8

(why??

Using the expression, everytime we encounter an operator, the operation must be done into the last 2 numbers before the operator.

= 8 10 * 3 7 + / //none happen

= 80 3 7 + / // 8*10=80

= 80 10 /  // 3+7=10

= 8 // 80/10=8

)

therefore, the value of the tree is 8.

problem 2:

make a tree for this expression and find the value. 8 10 * 3 7 + / –

solution:

the binary tree will be: therefore, the tree is invalid and the expression does not have a value

(why??

using the expression 8 10 * 3 7 + / -.

= 8 10 * 3 7 + / – //none happen

= 80 3 7 + / – // 8*10=80

= 80 10 / – // 3+7=10

= 8 – // 80/10=8

= 8 – // the operator minus (-) cannot find the other number before it for subtraction thus making the expression invalid.

)