construct an expression tree for the following prefix expression code example
Example: python build expression tree from prefix
class TreeNode:
"""Class for binary tree nodes."""
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_expression_tree_from_prefix(data):
"""
Returns the root of an expression tree built from 'Polish notation' (prefix).
### Parameters
- data (list) - a list of strings split from prefix expression.
"""
if not data:
return
stack = []
root = TreeNode(data[0])
stack.append(root)
stack.append(root)
for val in data[1:]:
curr = TreeNode(val)
if not root.left:
root.left = curr
else:
root.right = curr
root = curr
if root.val in '+-*/':
stack.append(root)
else:
root = stack.pop()
return root