作者:1994-MMMs | 来源:互联网 | 2023-05-18 18:16
PBSTNode deleteRRR(PBSTNode h,Key v)
{//删除一个匹配的键值,如果有重复的键,将删除
if (h == z)
{
return h;
}
PBSTNode p = h;
PBSTNode parent = NULL;
while (p != z)
{
if (p->data
{
parent = p;
p = p->right;
}
else if (p->data > v)
{
parent = p;
p = p->left;
}
else if (p->data == v)
{
if (parent)
{
PBSTNode x = p;
if (parent->data > v)
{
parent->left =joinLR(p->left,p->right);
p = parent->left;
}
else if (parent->data
{
parent->right =joinLR(p->left,p->right);
p = parent->right;
}
free(x);
}
else
{
PBSTNode x = p;
h =joinLR(p->left,p->right);
free(x);
p = h;
}
}
}
return h;
}