Skip to content

Conversation

@dimitrijjedich
Copy link
Collaborator

🌳❌🗑️ Binary tree delete operation

At the beginning the implementation was done without the option to delete a node from the tree. This should be implemented as methioned in the issue #23.

The logic

To delete a node from the tree not the node but instead the value of it is provided to the method.

the naming of pull resulted from the original implementation to add values which was called put

A pointer is then set to the root of the tree which is traveresed until a node is found with the provided value or the process hits a child with a null pointer.

Nothing found

In the case that the pointer hits a child with a null pointer, the return of the method is null, which inidicates that the provided values does not exist in the tree.

Update of parent

The found node, should it have a parent, needs to update them. This is done by checking if the found node is a left or a right child and then sets the child of the parent accordingly.

To determine the new child, a simple check for a left child is enought. If the left child does not exist, we just set the new child to the right child of the found node.

This handels 3 cases at once:

  1. There is a left child -> child of parent is updated to left child
  2. There is no left child -> child of parent is updated to right child
  3. There is no right child -> the found node is a leaf and therefore is replaced by null

@dimitrijjedich dimitrijjedich self-assigned this Jan 5, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 5, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
29.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants