Skip to content

Removing the root node in binary_search_tree.py removes the whole tree. #8715

Closed
@amirsoroush

Description

@amirsoroush

Repository commit

7310514

Python version (python --version)

Python 3.10.6

Dependencies version (pip freeze)

astroid==2.15.4
...

Expected behavior

https://github.com/TheAlgorithms/Python/blob/master/data_structures/binary_tree/binary_search_tree.py

Removing the root node should not delete the whole tree, it should behave just like removing any other nodes. It works fine if we delete other nodes but I guess because of the this line, it has problem when we remove the root node. There should be other checks as well.

Actual behavior

>>> t = BinarySearchTree()
>>> t.insert(1)
>>> t.insert(2)
>>> t.insert(3)
>>> t.remove(1)
>>> str(t)
'None'
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions