111
This commit is contained in:
@@ -13,6 +13,8 @@ class RBTreeNode {
|
||||
parent = null;
|
||||
color = null;
|
||||
Info = null;
|
||||
|
||||
name = null;
|
||||
constructor(key, func_info) {
|
||||
this.key = key;
|
||||
this.time = key;
|
||||
@@ -43,7 +45,7 @@ class RedBlackTree {
|
||||
this.root = this.nil;
|
||||
}
|
||||
|
||||
function insert(key, func_info) {
|
||||
function insert(key, func_info, gname = null) {
|
||||
local z = RBTreeNode(key, func_info);
|
||||
local y = this.nil;
|
||||
local x = this.root;
|
||||
@@ -66,6 +68,7 @@ class RedBlackTree {
|
||||
z.left = this.nil;
|
||||
z.right = this.nil;
|
||||
z.color = "red";
|
||||
if (gname) z.name = gname;
|
||||
this.insertFixup(z);
|
||||
this.size++;
|
||||
}
|
||||
@@ -286,4 +289,26 @@ class RedBlackTree {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function findNodeByName(node,name) {
|
||||
if (node == this.nil) {
|
||||
return null;
|
||||
}
|
||||
if (node.name == name) {
|
||||
return node;
|
||||
}
|
||||
local leftResult = findNodeByName(node.left, name);
|
||||
if (leftResult) {
|
||||
return leftResult;
|
||||
}
|
||||
return findNodeByName(node.right, name);
|
||||
}
|
||||
|
||||
// 新增方法:根据 name 移除节点
|
||||
function removeNodeByName(name) {
|
||||
local targetNode = this.findNodeByName(this.root,name);
|
||||
if (targetNode) {
|
||||
this.deleteNode(targetNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user