#ifndef DRAWVISITOR_H #define DRAWVISITOR_H #include "btnodevisitor.h" #include #include using namespace std; class drawVisitor : public btNodeVisitor, string> { public: string visit(binTreeNode *p, const pair& x) { stringstream s; typedef pair prstr; string lpad = x.first; string rpad = x.second; string pad = lpad.substr(0, lpad.size() - 1); if (p == 0) { return ""; } s << p->right->accept(*this, prstr( rpad + " |", rpad + " ")); s << pad << string("+--") << setw(3) << p->data << "\n"; s << p->left->accept(*this,prstr(lpad + " ", lpad + " |")); return s.str(); } }; #endif