Recursive Implementations 5: Display without Iterators
class PrintValue // function class to pass to Traverse()
{
public:
PrintValue (std::ostream& os, char ofc) : os_(os), ofc_(ofc) // constructor
{}
void operator() (const Node* n) const // evaluation operator
{
if (ofc_ == '\0')
os_ << n->value_;
else
os_ << n->value_ << ofc_;
}
private:
std::ostream& os_; // stored reference to os
char ofc_; // stored output formatting character
};
void Display (std::ostream& os, char ofc) const
{
PrintValue printval(os,ofc); // create function object
Traverse (printval); // call Traverse with f = printval
}