#include
#include
using namespace std;
template
class TreeNode {
public:
TreeNode(const T& val) : val_(val), left_(NULL), right_(NULL) {}
~TreeNode( ) {
delete left_;
delete right_;
}
const T& getVal( ) const {return(val_);}
void setVal(const T& val) {val_ = val;}
void addChild(TreeNode* p) {
const T& other = p->getVal( );
if (other > val_)
if (right_)
right_->addChild(p);
else
right_ = p;
else
if (left_)
left_->addChild(p);
else
left_ = p;
}
const TreeNode* getLeft( ) {return(left_);}
const TreeNode* getRight( ) {return(right_);}
private:
T val_;
TreeNode* left_;
TreeNode* right_;
};
int main( ) {
TreeNode node1("A");
TreeNode node2("B");
TreeNode node3("C");
node1.addChild(&node2);
node1.addChild(&node3);
}