Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b7e27b2

Browse files
committed
Remove parent parameter from binary tree node constructor to simplify syntax.
1 parent fcc5463 commit b7e27b2

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

‎src/data-structures/tree/BinaryTreeNode.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import Comparator from '../../utils/comparator/Comparator';
33
export default class BinaryTreeNode {
44
/**
55
* @param {*} [value]
6-
* @param {BinaryTreeNode} [parent]
76
*/
8-
constructor(value = null,parent=null) {
7+
constructor(value = null) {
98
this.left = null;
109
this.right = null;
11-
this.parent = parent;
10+
this.parent = null;
1211
this.value = value;
1312

1413
// This comparator is used to compare binary tree nodes with each other.

‎src/data-structures/tree/binary-search-tree/BinarySearchTree.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default class BinarySearchTree {
66
*/
77
constructor(nodeValueCompareFunction) {
88
this.nodeValueCompareFunction = nodeValueCompareFunction;
9-
this.root = new BinarySearchTreeNode(null, null,this.nodeValueCompareFunction);
9+
this.root = new BinarySearchTreeNode(null, this.nodeValueCompareFunction);
1010
}
1111

1212
/**

‎src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import Comparator from '../../../utils/comparator/Comparator';
44
export default class BinarySearchTreeNode extends BinaryTreeNode {
55
/**
66
* @param {*} [value]
7-
* @param {BinaryTreeNode} [parent]
87
* @param {function} [compareFunction]
98
*/
10-
constructor(value = null, parent=null,compareFunction = undefined) {
11-
super(value,parent);
9+
constructor(value = null, compareFunction = undefined) {
10+
super(value);
1211

1312
// This comparator is used to compare node values with each other.
1413
this.compareFunction = compareFunction;
@@ -30,14 +29,14 @@ export default class BinarySearchTreeNode extends BinaryTreeNode {
3029
if (this.left) {
3130
this.left.insert(value);
3231
} else {
33-
this.setLeft(new BinarySearchTreeNode(value, null,this.compareFunction));
32+
this.setLeft(new BinarySearchTreeNode(value, this.compareFunction));
3433
}
3534
} else if (this.nodeValueComparator.greaterThan(value, this.value)) {
3635
// Insert to the right.
3736
if (this.right) {
3837
this.right.insert(value);
3938
} else {
40-
this.setRight(new BinarySearchTreeNode(value, null,this.compareFunction));
39+
this.setRight(new BinarySearchTreeNode(value, this.compareFunction));
4140
}
4241
}
4342

‎src/data-structures/tree/binary-search-tree/__test__/BinarySearchTreeNode.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ describe('BinarySearchTreeNode', () => {
188188
const obj2 = { key: 'obj2', value: 2, toString: () => 'obj2' };
189189
const obj3 = { key: 'obj3', value: 3, toString: () => 'obj3' };
190190

191-
const bstNode = new BinarySearchTreeNode(obj2, null,nodeValueComparatorCallback);
191+
const bstNode = new BinarySearchTreeNode(obj2, nodeValueComparatorCallback);
192192
bstNode.insert(obj1);
193193

194194
expect(bstNode.toString()).toBe('obj1,obj2');

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /