Question: Let's also allow decimal input and output, and negative numbers. For simplicity, all tokens in the input string be separated by a space. Build a

Let's also allow decimal input and output, and negative numbers. For simplicity, all tokens in the input string be separated by a space. Build a BXT You need to change the string into a tree. Hint1: In a postfix string the operator is preceded by two operands (numbers). This suggests a stack of TreeNodes would be useful. Hint 2: Each operator is a TreeNode with two children. Hint 3: If the token is an operator, do what? Else it's a number, so do what? Display Infix and Prefix orders Refer to the previous assignments if you forgot. Evaluating the Expression Do this recursively. If the node is an operator, recursively evaluate the left child and the right child, and return the result. Else the node is a number, so it can be converted into a double, and returned. Want to do more? (Optional) Print the infix order with parentheses.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!