Question: An arithmetic expression can be represented using a binary tree whose leaves are associated with variables or constants, and whose internal nodes are associated with
An arithmetic expression can be represented using a binary tree whose leaves are associated with variables or constants, and whose internal nodes are associated with one of the operators +, -, *, and I. Each node has a value associated with it. Write an implementation of the BiExpTree class. You can use either array-based or linked-based implementation. The B?ExpTree class has the following methods: 1. BiExpTree: to construct an empty binary expression tree 2. CreateExp (exp) takes a fully parenthesized expression and builds a binary expression tree representation for it. You may assume that all operators are values (variables are not required). 3. prefix displays the prefix form of the expression 4. infix0: displays the infix form of the expression stored in the 5. evalExp: evaluates the arithmetic expression stored in the II. The Menu-driven Program: stored in the calling BiExpTree object. calling BiExpTree object calling BiExpTree object and returns its value. Write a menu-driven program builder and evaluator. The menu includes the following options to implement an expression t ree 1. Input new arithmetic expression. The program prompt the user to enter a fully parenthesized arithmetic expression. A binary expression tree corresponding to that expression is created. You may assume that only valid input is expected 2. Display prefix form of expression. The programw invoke the prefix) method from the B?ExpTree class to display a prefix form of the expression. 3. Display infix form of expression. The program wl invoke the infix0 method from the B?ExpTree class to display an infix form of the expression. 4. Evaluate expression. The program will call the EvalExpr0 method from the B?ExpTree class. 5. Exit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
