Question: . In C++: Construct the expression tree of slide 14 of week 4 and run FCS eval operation on it (make a C++ adaptation of

. In C++: Construct the expression tree of slide 14 of week 4 and run FCS eval operation on it (make a C++ adaptation of the FCS C code of Figure 5.19). Demonstrate that the outcome is properly computed. Slide 14 shows (1 +2) * (3+4)

fig 5.19:

typedef struct NODE *pNODE; struct NODE { char op; int value; pNODE leftmostChild, rightSibling; }; int eval(pNODE n) { int val1, val2; /* values of first and second subtrees */ if (n->op == 'i') /* n points to a leaf */ return n->value; else { /* n points to an interior node */ val1 = eval(n->leftmostChild); val2 = eval(n->leftmostChild->rightSibling); switch (n->op) { case '+': return val1 + val2; case '-': return val1 - val2; case '*': return val1 * val2; case '/': return val1 / val2; } } }

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!