}
else
{
suc=next ( drop->right);
value=drop->m_data;
drop->m_data=suc->m_data;
suc->m_data=value;
if(suc->parent->left==suc)
{
mode=0;
}
else
{
mode=1;
}
if(!suc->right)
{
if(0==mode)
{
suc->parent->left=0;
}
else
{
suc->parent->right=0;
}
myfree(suc);
}
else
{
if(0==mode)
{
suc->parent->left=suc->right;
}
else
{
suc->parent->right=suc->right;
}
curnode=suc->right;
curnode->parent=suc->parent;
myfree(suc);
delete_fixup (node ,curnode,mode);
}
}
node->size--;
}
else
{
}
node->root->m_color=BLACK;
}
void insert ( wrapdata *node , int data )
{
redblack *newnode;
redblack *curnode;
int relation;
node->size++;
newnode=newstruct (data);
// printf("will insert %x %d \n",newnode,data);
if ( ! node->root)
{
node->root= newnode;
}
else
{
curnode=node->root;
while(1)
{
relation=compare(data,curnode);
if(relation==-1)
{
node->size--;
myfree(newnode);
return ;
}
else
{
if ( relation==1)
{
if (!curnode->right)
{
curnode->right=newnode;
newnode->parent=curnode;
break;
}
else
{
curnode=curnode->right;
}
}
else
{
if (!curnode->left)
{
curnode->left=newnode;
newnode->parent=curnode;
break;
}
else
{
curnode=curnode->left;
}
}
}
}
insert_fixup ( node , newnode);
}
node->root->m_color=BLACK;
}