Add binary search tree.

This commit is contained in:
Oleksii Trekhleb
2018-04-03 07:50:30 +03:00
parent b89e406444
commit 1c911aadf0
4 changed files with 22 additions and 4 deletions

View File

@@ -23,6 +23,21 @@ describe('BinaryTreeNode', () => {
expect(rootNode.right.value).toBe(3);
});
it('should set parent', () => {
const leftNode = new BinaryTreeNode(1);
const rightNode = new BinaryTreeNode(3);
const rootNode = new BinaryTreeNode(2);
rootNode
.setLeft(leftNode)
.setRight(rightNode);
expect(rootNode.parent).toBeNull();
expect(rootNode.left.parent.value).toBe(2);
expect(rootNode.right.parent.value).toBe(2);
expect(rootNode.right.parent).toEqual(rootNode);
});
it('should traverse node', () => {
const leftNode = new BinaryTreeNode(1);
const rightNode = new BinaryTreeNode(3);