This commit is contained in:
lenheart
2025-04-21 13:36:35 +08:00
parent eeb773e723
commit 2ef9cfef42
87 changed files with 2134 additions and 765 deletions

View File

@@ -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);
}
}
}