typescript-algorithms-and-datastructures
Version:
Useful algorithms and Data structures written in typescript.
50 lines • 1.51 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class BinaryTreeNode {
constructor(value, parent) {
this.left = null;
this.right = null;
this.parent = null;
this.value = value;
this.parent = parent;
}
hasLeftChild() {
return this.left !== null;
}
hasRightChild() {
return this.right !== null;
}
isLeftChild() {
return this.parent && this.parent.left === this;
}
isRightChild() {
return this.parent && this.parent.right === this;
}
isRoot() {
return this.parent === null;
}
min() {
if (this.left !== null) {
return this.left.min();
}
return this;
}
max() {
if (this.right !== null) {
return this.right.max();
}
return this;
}
}
exports.BinaryTreeNode = BinaryTreeNode;
});
//# sourceMappingURL=BinaryTreeNode.js.map