Skip to content

Commit

Permalink
Fix bug for the remove method of BinarySearchTree (aalhour#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijli authored and MetSystem committed Sep 6, 2018
1 parent eba4e2f commit 76e46e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DataStructures/Trees/AugmentedBinarySearchTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected bool _remove(BSTRankedNode<T> node)

if (node.ChildrenCount == 2) // if both children are present
{
var successor = node.RightChild;
var successor = _findNextLarger(node);
node.Value = successor.Value;
return (true && _remove(successor));
}
Expand Down
6 changes: 5 additions & 1 deletion DataStructures/Trees/BinarySearchTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ protected virtual void _replaceNodeInParent(BSTNode<T> node, BSTNode<T> newNode
else
node.Parent.RightChild = newNode;
}
else
{
Root = newNode;
}

if (newNode != null)
newNode.Parent = node.Parent;
Expand All @@ -96,7 +100,7 @@ protected virtual bool _remove(BSTNode<T> node)

if (node.ChildrenCount == 2) // if both children are present
{
var successor = node.RightChild;
var successor = _findNextLarger(node);
node.Value = successor.Value;
return (true && _remove(successor));
}
Expand Down

0 comments on commit 76e46e1

Please sign in to comment.