Skip to content

Commit

Permalink
fixed error and added test method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ira Fesefeldt committed Nov 15, 2023
1 parent f1ecbf6 commit 6061b70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions pyalgotask/tasks/trees/avl_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def insert(self, value):
self.adjust_depth(new_node.parent)

# rebalance (A7-A9)
self.balance(new_node)
root = self.balance(new_node)
self.algorithm_root = root

def adjust_depth(self, node):
"""adjusts the depth values starting from node
Expand Down Expand Up @@ -140,8 +141,9 @@ def balance(self, node):
:return: the new root of the tree
"""
if node.is_nil():
return
return node

child = node
current = node.parent
while not current.is_nil():
if current.left.depth == current.right.depth + 2:
Expand All @@ -151,8 +153,11 @@ def balance(self, node):
# right imbalance
current = self.balance_right(current)

child = current
current = current.parent

return child

def delete(self, value):
"""Performs a delete of the value from the tree
:param value: the value to delete
Expand Down Expand Up @@ -209,7 +214,7 @@ def algorithm(self):
raise NotImplementedError(
f"Operator {operation.type} not supported by task {self.__class__.__name__}"
)
yield (self.algorithm_root, str(operation))
yield (self.algorithm_root, operation)


task_base.register_task("tree", AVLTree())
2 changes: 1 addition & 1 deletion pyalgotask/tasks/trees/binary_search_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def algorithm(self):
raise NotImplementedError(
f"Operator {operation.type} not supported by task {self.__class__.__name__}"
)
yield (self.algorithm_root, str(operation))
yield (self.algorithm_root, operation)


task_base.register_task("tree", BinarySearchTree())

0 comments on commit 6061b70

Please sign in to comment.