mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-26 02:48:40 +00:00
is right test
This commit is contained in:
parent
07de23f04e
commit
9f5f4ffcd5
@ -38,6 +38,11 @@ True
|
|||||||
>>> t.search(-1) is not None
|
>>> t.search(-1) is not None
|
||||||
False
|
False
|
||||||
|
|
||||||
|
>>> t.search(6).is_right
|
||||||
|
True
|
||||||
|
>>> t.search(1).is_right
|
||||||
|
False
|
||||||
|
|
||||||
>>> t.get_max().value
|
>>> t.get_max().value
|
||||||
14
|
14
|
||||||
>>> t.get_min().value
|
>>> t.get_min().value
|
||||||
@ -177,12 +182,12 @@ class BinarySearchTree:
|
|||||||
elif node.right is None: # Has only left children
|
elif node.right is None: # Has only left children
|
||||||
self.__reassign_nodes(node, node.left)
|
self.__reassign_nodes(node, node.left)
|
||||||
else:
|
else:
|
||||||
tmp_node = self.get_max(
|
predecessor = self.get_max(
|
||||||
node.left
|
node.left
|
||||||
) # Gets the max value of the left branch
|
) # Gets the max value of the left branch
|
||||||
self.remove(tmp_node.value) # type: ignore
|
self.remove(predecessor.value) # type: ignore
|
||||||
node.value = (
|
node.value = (
|
||||||
tmp_node.value # type: ignore
|
predecessor.value # type: ignore
|
||||||
) # Assigns the value to the node to delete and keep tree structure
|
) # Assigns the value to the node to delete and keep tree structure
|
||||||
|
|
||||||
def preorder_traverse(self, node: Node | None) -> Iterable:
|
def preorder_traverse(self, node: Node | None) -> Iterable:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user