// Textbook fragment 07.31 /** Compute the value of an arithmetic expression tree. */ public class EvaluateExpressionTour extends EulerTour { public Integer execute(BinaryTree T) { init(T); // calls method of superclass return eulerTour(tree.root()); // returns the value of the expression } protected void visitRight(Position v, TourResult r) { ExpressionTerm term = v.element(); if (tree.isInternal(v)) { ExpressionOperator op = (ExpressionOperator) term; op.setOperands(r.left, r.right); } r.out = term.getValue(); } }