Code Fragment: EvaluateExpressionTour



template <typename BinaryTree>
class EvaluateExpressionTour : public EulerTour<BinaryTree> {
public:
  void execute(const BinaryTree& T) {			// execute the tour
    initialize(T);
    std::cout << "The value is: " << eulerTour(tree->root()) << "\n";
  }
protected:                                      	// leaf: return value
  typedef EulerTour<BinaryTree>::Position	    Position;
  typedef EulerTour<BinaryTree>::TraversalResult    TraversalResult;
  virtual void visitExternal(const Position& v, TraversalResult& r) const
    { r.finalResult = v.element().value(); }
							// internal: do operation
  virtual void visitRight(const Position& v, TraversalResult& r) const
    { r.finalResult = v.element().operation(r.leftResult, r.rightResult); }
};