Fix issue #98.

This commit is contained in:
Oleksii Trekhleb
2018-07-13 17:48:27 +03:00
parent fafa52c26e
commit 863dbdbac3
2 changed files with 12 additions and 0 deletions

View File

@ -132,6 +132,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
}
}
// Clear the parent of removed node.
nodeToRemove.parent = null;
return true;
}

View File

@ -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();
});
});