Skip to content

Commit

Permalink
Fix issue trekhleb#98.
Browse files Browse the repository at this point in the history
  • Loading branch information
trekhleb committed Jul 13, 2018
1 parent fafa52c commit 863dbdb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
}
}

// Clear the parent of removed node.
nodeToRemove.parent = null;

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,13 @@ describe('BinarySearchTreeNode', () => {

expect(bstNode.findMin().value).toEqual(obj1);
});

it('should abandon removed node', () => {
const rootNode = new BinarySearchTreeNode('foo');
rootNode.insert('bar');
const childNode = rootNode.find('bar');
rootNode.remove('bar');

expect(childNode.parent).toBeNull();
});
});

0 comments on commit 863dbdb

Please sign in to comment.