// Textbook fragment 07.32 /** Print out the expression stored in an arithmetic expression tree. */ public class PrintExpressionTour extends EulerTour { public String execute(BinaryTree T) { init(T); System.out.print("Expression: "); eulerTour(T.root()); System.out.println(); return null; // nothing to return } protected void visitLeft(Position v, TourResult r) { if (tree.isInternal(v)) System.out.print("("); } protected void visitBelow(Position v, TourResult r) { System.out.print(v.element()); } protected void visitRight(Position v, TourResult r) { if (tree.isInternal(v)) System.out.print(")"); } }