so i have a binary tree and a postfix expression "6 2 * 3 /" what is the algo to put it in a tree? like,
[/]
/ \
[*] [3]
/ \
[6] [2]
To construct a tree from the expression, pretend you are evaluating it directly but construct trees instead of calculating numbers. (This trick works for many more things than postfix expressions.)
Algorithm: Have a stack to store intermediate values (which are trees), and examine each token from left to right:
At the end, if the expression is properly formed, then you should have exactly one tree on the stack which is the entire expression in tree form.