diff --git a/src/data-structures/tree/BinaryTreeNode.js b/src/data-structures/tree/BinaryTreeNode.js index 8796abc1..e894792c 100644 --- a/src/data-structures/tree/BinaryTreeNode.js +++ b/src/data-structures/tree/BinaryTreeNode.js @@ -3,12 +3,11 @@ import Comparator from '../../utils/comparator/Comparator'; export default class BinaryTreeNode { /** * @param {*} [value] - * @param {BinaryTreeNode} [parent] */ - constructor(value = null, parent = null) { + constructor(value = null) { this.left = null; this.right = null; - this.parent = parent; + this.parent = null; this.value = value; // This comparator is used to compare binary tree nodes with each other. diff --git a/src/data-structures/tree/binary-search-tree/BinarySearchTree.js b/src/data-structures/tree/binary-search-tree/BinarySearchTree.js index 4c2f855d..77cc998a 100644 --- a/src/data-structures/tree/binary-search-tree/BinarySearchTree.js +++ b/src/data-structures/tree/binary-search-tree/BinarySearchTree.js @@ -6,7 +6,7 @@ export default class BinarySearchTree { */ constructor(nodeValueCompareFunction) { this.nodeValueCompareFunction = nodeValueCompareFunction; - this.root = new BinarySearchTreeNode(null, null, this.nodeValueCompareFunction); + this.root = new BinarySearchTreeNode(null, this.nodeValueCompareFunction); } /** diff --git a/src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js b/src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js index f3726cb2..8f457e3b 100644 --- a/src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js +++ b/src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js @@ -4,11 +4,10 @@ import Comparator from '../../../utils/comparator/Comparator'; export default class BinarySearchTreeNode extends BinaryTreeNode { /** * @param {*} [value] - * @param {BinaryTreeNode} [parent] * @param {function} [compareFunction] */ - constructor(value = null, parent = null, compareFunction = undefined) { - super(value, parent); + constructor(value = null, compareFunction = undefined) { + super(value); // This comparator is used to compare node values with each other. this.compareFunction = compareFunction; @@ -30,14 +29,14 @@ export default class BinarySearchTreeNode extends BinaryTreeNode { if (this.left) { this.left.insert(value); } else { - this.setLeft(new BinarySearchTreeNode(value, null, this.compareFunction)); + this.setLeft(new BinarySearchTreeNode(value, this.compareFunction)); } } else if (this.nodeValueComparator.greaterThan(value, this.value)) { // Insert to the right. if (this.right) { this.right.insert(value); } else { - this.setRight(new BinarySearchTreeNode(value, null, this.compareFunction)); + this.setRight(new BinarySearchTreeNode(value, this.compareFunction)); } } diff --git a/src/data-structures/tree/binary-search-tree/__test__/BinarySearchTreeNode.test.js b/src/data-structures/tree/binary-search-tree/__test__/BinarySearchTreeNode.test.js index 18c2f8f0..dfe733c8 100644 --- a/src/data-structures/tree/binary-search-tree/__test__/BinarySearchTreeNode.test.js +++ b/src/data-structures/tree/binary-search-tree/__test__/BinarySearchTreeNode.test.js @@ -188,7 +188,7 @@ describe('BinarySearchTreeNode', () => { const obj2 = { key: 'obj2', value: 2, toString: () => 'obj2' }; const obj3 = { key: 'obj3', value: 3, toString: () => 'obj3' }; - const bstNode = new BinarySearchTreeNode(obj2, null, nodeValueComparatorCallback); + const bstNode = new BinarySearchTreeNode(obj2, nodeValueComparatorCallback); bstNode.insert(obj1); expect(bstNode.toString()).toBe('obj1,obj2');