mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-07 09:54:53 +08:00
Fix issue #98.
This commit is contained in:
@ -132,6 +132,9 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the parent of removed node.
|
||||
nodeToRemove.parent = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user