-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary-tree-node.js
More file actions
51 lines (45 loc) · 926 Bytes
/
binary-tree-node.js
File metadata and controls
51 lines (45 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
/**
* Creates a binary tree node.
*
* @constructor
* @param {Object} key The key of the node.
* @param {BinaryTreeNode} parent The parent of the node.
*/
function BinaryTreeNode(key, parent) {
/**
* The key of the node.
* @public
*/
this.key = key;
/**
* The parent of the node.
* @public
*/
this.parent = parent;
/**
* The left child of the node.
* @public
*/
this.left = undefined;
/**
* The right child of the node.
* @public
*/
this.right = undefined;
}
/**
* Removes a child from the node. This will remove the left or right node
* depending on which one matches the argument.
*
* @param {Object} node The node to remove.
*/
BinaryTreeNode.prototype.removeChild = function (node) {
if (this.left === node) {
this.left = undefined;
}
if (this.right === node) {
this.right = undefined;
}
};
module.exports = BinaryTreeNode;