mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +08:00
Throw error on remove from red-black tree.
This commit is contained in:
parent
26d6b7877d
commit
0edb1525ea
@ -32,6 +32,14 @@ export default class RedBlackTree extends BinarySearchTree {
|
|||||||
return insertedNode;
|
return insertedNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {*} value
|
||||||
|
* @return {BinarySearchTreeNode}
|
||||||
|
*/
|
||||||
|
remove(value) {
|
||||||
|
throw new Error(`Can't remove ${value}. Remove method is not implemented yet`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {BinarySearchTreeNode} node
|
* @param {BinarySearchTreeNode} node
|
||||||
*/
|
*/
|
||||||
|
@ -311,4 +311,14 @@ describe('RedBlackTree', () => {
|
|||||||
expect(tree.toString()).toBe('15,17,19,20,25');
|
expect(tree.toString()).toBe('15,17,19,20,25');
|
||||||
expect(tree.root.height).toBe(2);
|
expect(tree.root.height).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw an error when trying to remove node', () => {
|
||||||
|
const removeNodeFromRedBlackTree = () => {
|
||||||
|
const tree = new RedBlackTree();
|
||||||
|
|
||||||
|
tree.remove(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(removeNodeFromRedBlackTree).toThrowError();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user