-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbinary-tree-node.js
More file actions
63 lines (56 loc) · 1.3 KB
/
Copy pathbinary-tree-node.js
File metadata and controls
63 lines (56 loc) · 1.3 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @module lib/binary-tree-node
* @license MIT Copyright 2014 Daniel Imms (http://www.growingwiththeweb.com)
*/
'use strict';
if (typeof exports === 'object' && typeof define !== 'function') {
var define = function (factory) {
factory(require, exports, module);
};
}
define(function (require, exports, module) {
/**
* 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;
});