К
Size: a a a
К
К
S
К
S
К
C
К
C
C
К
binary_tree<int>* bin = new binary_tree<int>();
bin->add(5)->add(4)->add(3)->add(6)->add(10)->add(8)->add(7)->add(-2)->add(-1)->add(-3);GG
C
GG
GG
T
binary_tree* add(T data) {
binary_tree* cur = this;
while (cur) {
if (data < cur->data) {
if (cur->left) {
cur = cur->left;
std::cout << "Left" << std::ends;
continue;
}
else {
cur->left = new binary_tree<int>(data);
std::cout << "in Left " << data << std::endl;
break;
}
}
else if (data > cur->data) {
if (cur->right) {
cur = cur->right;
std::cout << "Right" << std::ends;
continue;
}
else {
cur->right = new binary_tree<int>(data);
std::cout << "in Right " << data << std::endl;
break;
}
}
}
return this;
}T
binary_tree* add(T data) {
binary_tree* cur = this;
while (cur) {
if (data < cur->data) {
if (cur->left) {
cur = cur->left;
std::cout << "Left" << std::ends;
continue;
}
else {
cur->left = new binary_tree<int>(data);
std::cout << "in Left " << data << std::endl;
break;
}
}
else if (data > cur->data) {
if (cur->right) {
cur = cur->right;
std::cout << "Right" << std::ends;
continue;
}
else {
cur->right = new binary_tree<int>(data);
std::cout << "in Right " << data << std::endl;
break;
}
}
}
return this;
}