Question
Given an expression tree, write a method to evaluate it and return its value. Assume that the Token class has a member function long getValue()
Given an expression tree, write a method to evaluate it and return its value. Assume that the Token class has a member function "long getValue()" that returns the value of a token that is an operand. Token class has a field "Token Type token" which takes one of the following four values when the token is an operator. {PLUS, MINUS, TIMES, DIV}, corresponding to the operators {+, -,*, /}. In expression trees, internal nodes are operator nodes and leaf nodes are operands Make additional assumptions as needed as in Project 1
class Expression {Token toke; Expression left, right ; }
Long evaluateExpTree { Expression tree}{
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started