Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 31b6a08

Browse files
committedOct 13, 2024·
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 20aed9e commit 31b6a08

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

‎data_structures/binary_tree/avl_tree.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,26 @@ def get_left_most(root: MyNode) -> Any:
194194
root = left_child
195195
return root.get_data()
196196

197+
197198
# Function to get balance factor
198199
def get_balance(node: MyNode) -> int:
199200
if node is None:
200201
return 0
201202
return get_height(node.get_left()) - get_height(node.get_right())
202203

204+
203205
def get_min_value_node(node: MyNode) -> MyNode:
204206
current = node
205207
while current.get_left() is not None:
206208
current = current.get_left()
207209
return current
208210

211+
209212
def del_node(root: MyNode, data: Any) -> MyNode | None:
210213
if root is None:
211214
print("Nothing to delete")
212215
return None
213-
216+
214217
if root.get_data() > data:
215218
root.set_left(del_node(root.get_left(), data))
216219
elif root.get_data() < data:
@@ -227,7 +230,9 @@ def del_node(root: MyNode, data: Any) -> MyNode | None:
227230
root.set_data(temp.get_data())
228231
root.set_right(del_node(root.get_right(), temp.get_data()))
229232

230-
root.set_height(1 + my_max(get_height(root.get_left()), get_height(root.get_right())))
233+
root.set_height(
234+
1 + my_max(get_height(root.get_left()), get_height(root.get_right()))
235+
)
231236

232237
balance = get_balance(root)
233238

@@ -251,6 +256,7 @@ def del_node(root: MyNode, data: Any) -> MyNode | None:
251256

252257
return root
253258

259+
254260
class AVLtree:
255261
"""
256262
An AVL tree doctest

0 commit comments

Comments
 (0)
Please sign in to comment.