Beispiel #1
0
RBTree::Node *RBTree::rb_presuccessor(Node *nd)
{
	if(nd == NIL)
		return NIL;

	if(nd->left != NIL)
		return rb_maximum(nd->left);
	while(nd->parent!=NIL && nd!=nd->parent->right)
		nd = nd->parent;
	return nd->parent;
}
Beispiel #2
0
rb_node_t* rb_predecessor(rb_node_t* nodex)
{
	rb_node_t* nodey;

	if(nodex->lchild != &nil)
	{
		return rb_maximum(nodex->rchild);
	}

	nodey = nodex->parent;
	while (nodey != &nil && nodex == nodey->lchild)
	{
		nodex = nodey;
		nodey = nodey->parent;
	}
	return nodey;
}