How should we construct the binary tree of the following "prefix" order expression?
( - * / 8 + 5 1 4 + 3 - 5 / 18 6 ) 4
Pseudocode is like this:
public ExpressionRootNode MakeBinaryTree(expr):
element = next element in expr
if element is a number:
return a leaf node of that number
else: // element is an operator
left = MakeBinaryTree(expr)
right = MakeBinaryTree(expr)
return a binary tree with subtrees left and right and with operator element
//^aka return root
However, I dont quite understand how to recursively call the function to create said tree. I have tried looking at how to Create a binary tree from an algebraic expression, but can't figure out how to backtrack up to the other node.
Project files : http://pastebin.com/BJiPtDM5, its a mess.