Answered step by step
Verified Expert Solution
Question
1 Approved Answer
QUESTION-5) [15 points] The following is a Binary Tree representing an arithmetic expression. The example tree represents the expression (3+1)x3)/((9-5)+2))-((3x(7-4))+6)). For leaf nodes, the
QUESTION-5) [15 points] The following is a Binary Tree representing an arithmetic expression. The example tree represents the expression (3+1)x3)/((9-5)+2))-((3x(7-4))+6)). For leaf nodes, the symbol can be a constant between 'O' and '9'. For other nodes, the symbol can be one of the operators +,-,x,/. The struct Node definition is given as below. struct Node { char symbol; struct Node * left, * right; Write the recursive C function whose prototype is given below. float Calculate (struct Node * P); Function takes the root of a binary expression tree as parameter (P). Function should calculate and return the float result of the arithmetic expression. If a node is a leaf, then function should return the numerical equivalent of the constant. Example: If the symbol is constant '4', then function should return 4.0 If a node is non-leaf, then function should calculate and return the result by applying its arithmetic operator to the results of its left branch and right branch.
Step by Step Solution
★★★★★
3.40 Rating (147 Votes )
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