Skip to content

Commit 07de23f

Browse files
committed
moved is_right to property
1 parent 8510e1f commit 07de23f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: data_structures/binary_tree/binary_search_tree.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def __repr__(self) -> str:
6868
return str(self.value)
6969
return pformat({f"{self.value}": (self.left, self.right)}, indent=1)
7070

71+
@property
72+
def is_right(self) -> bool:
73+
if self.parent and self.parent.right:
74+
return self == self.parent.right
75+
return False
76+
7177

7278
class BinarySearchTree:
7379
def __init__(self, root: Node | None = None):
@@ -83,18 +89,13 @@ def __reassign_nodes(self, node: Node, new_children: Node | None) -> None:
8389
if new_children is not None: # reset its kids
8490
new_children.parent = node.parent
8591
if node.parent is not None: # reset its parent
86-
if self.is_right(node): # If it is the right children
92+
if node.is_right: # If it is the right children
8793
node.parent.right = new_children
8894
else:
8995
node.parent.left = new_children
9096
else:
9197
self.root = None
9298

93-
def is_right(self, node: Node) -> bool:
94-
if node.parent and node.parent.right:
95-
return node == node.parent.right
96-
return False
97-
9899
def empty(self) -> bool:
99100
return self.root is None
100101

0 commit comments

Comments
 (0)