/*** @file 二叉树th实现**/
class BinNode {
constructor(data, parent = null, leftNode = null, rightNode = null) {
this.data = data;
this.lChild = leftNode;
this.rChild = rightNode;
this.parent = parent;
this.height = 0;
// 左式堆 留给以后 this.npl = null;
// 红黑树 留给以后 this.color = null;
this.size();
}
print() {
console.log('node:', this);
}
visit() {
console.log('node data:', this.data);
return this.data;
}
// 获取子树规模 size() {
let s = 1;
if (this.lChild) {
s += this.lChild.size();
}
if (this.rChild) {
s += this.rChild.size();
}
return s;
}
// 作为左孩子插入新的节点 insertAsLC(newNode) {<