Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


🌳❌🗑️ 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.
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
nullpointer.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: