Given the postfix
tokens of an arithmetic expression, build and return the binary expression tree that represents this expression.
Postfix notation is a notation for writing arithmetic expressions in which the operands (numbers) appear before their operators. For example, the postfix tokens of the expression 4*(5-(7+2))
are represented in the array postfix = ["4","5","7","2","+","-","*"]
.
The class Node
is an interface you should use to implement the binary expression tree. The returned tree will be tested using the evaluate
function, which is supposed to evaluate the tree's value. You should not remove the Node
class; however, you can modify it as you wish, and you can define other classes to implement it if needed.
A binary expression tree is a kind of binary tree used to represent arithmetic expressions. Each node of a binary expression tree has either zero or two children. Leaf nodes (nodes with 0 children) correspond to operands (numbers), and internal nodes (nodes with two children) correspond to