9template<
typename ElementType>
23 node(ElementType value=ElementType{}):
34 if(value < this->m_value)
37 this->m_left->
insert(value);
39 this->m_left.reset(
new node{value});
41 else if(value > this->m_value)
44 this->m_right->
insert(value);
46 this->m_right.reset(
new node{value});
55 os<<
"node_" << this->m_value;
64 <<
" [ shape=oval, label=\" "
65 << this->m_value <<
" \"]";
75 << this->m_left->get_node_name() <<
";" <<
std::endl;
77 this->m_left->print_node(os);
83 << this->m_right->get_node_name() <<
";" <<
std::endl;
85 this->m_right->print_node(os);
108 this->m_left->print(bLeft);
110 stream <<
"{ " << this->m_value <<
", "
111 << this->m_balance <<
" }" <<
endl;
114 this->m_right->print(bLeft);
119 this->m_right->print(bLeft);
121 stream <<
"{ " << this->m_value <<
", "
122 << this->m_balance <<
" }" <<
endl;
125 this->m_left->print(bLeft);
130 int main(
int argc,
const char* argv[])
134 stream <<
"Usage: " << argv[0] <<
" [list of node values] " <<
endl;
140 for(
int i=2; i < argc; ++i)
142 root.
insert(std::atoi(argv[i]));
int main(int argc, const char *argv[])
string_t get_node_definition()
node(ElementType value=ElementType{})
void print_node(std::stringstream &os)
void print(bool bLeft=true)
const node_ptr_t & right() const
std::unique_ptr< node > node_ptr_t
node & insert(ElementType value)
const node_ptr_t & left() const
Stream output operators << are implemented.