mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Fix BST removal method (#74)
* Fix LinkedList * Fix the prepend method for the LinkedList * Fix the remove method for the MinHeap * Correct a comment * Fix BST removal method
This commit is contained in:
committed by
Oleksii Trekhleb
parent
e558231474
commit
bd5a16be71
@@ -185,6 +185,21 @@ describe('BinarySearchTreeNode', () => {
|
||||
expect(bstRootNode.toString()).toBe('30');
|
||||
});
|
||||
|
||||
it('should remove node with no parent', () => {
|
||||
const bstRootNode = new BinarySearchTreeNode();
|
||||
expect(bstRootNode.toString()).toBe('');
|
||||
|
||||
bstRootNode.insert(1);
|
||||
bstRootNode.insert(2);
|
||||
expect(bstRootNode.toString()).toBe('1,2');
|
||||
|
||||
bstRootNode.remove(1);
|
||||
expect(bstRootNode.toString()).toBe('2');
|
||||
|
||||
bstRootNode.remove(2);
|
||||
expect(bstRootNode.toString()).toBe('');
|
||||
});
|
||||
|
||||
it('should throw error when trying to remove not existing node', () => {
|
||||
const bstRootNode = new BinarySearchTreeNode();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user