Cześć. Kiedy chcę wyświetlić na terminal coś z korzenia drzewa binarnego wychodzą mi błędne dane.
main.cpp :
int main()
{
Bst<int>* drzewo = new Bst<int>();
drzewo->add_new(100);
drzewo->display();
delete drzewo;
return 0;
}
bst.h :
template <class T>
class Bst {
[...]
Bst() { }
[...]
void display() {
if (!root) {
std::cout << "binary search tree is empty" << std::endl;
}
else {
std::cout << "binary search tree:\nsize: " << size << "\nheight: " << height << "\n0 = nullptr\n";
std::cout << "{\n(" << root->index << ": [p: 0, l: " << ((root->left != nullptr) ? 0 : root->left->index) << ", r: " << ((root->right != nullptr) ? 0 : root->right->index) << "], data: " << root->data << ")\n";
}
std::cout << std::endl;
}
** całość kodu: https://godbolt.org/z/oGasv8 **