the tree node contains pointers to its two children , a pointer to its parent
and a pointer to the data
but the delete Method does not work properly and i'm trying to figrue out what's wrong with it
sometimes it deletes the right key but sometimes not
/******************************************************
*Deletes a node from the tree and returns its pointer *
******************************************************/
Node* Dictionary::Delete(Node *&curr)
{
Node *x=NULL,*y=NULL;
if (curr->left==NULL || curr->right==NULL)
{
y=curr;
}
else
{
y=find_Insucc(curr);
}
if (y->left!=NULL)
{
x=y->left;
}
else
{
x=y->right;
}
if (x!=NULL)
{
x->Parent=y->Parent;
}
if (y->Parent==NULL)
{
root=x;
}
else if (y==y->Parent->left)
{
y->Parent->left=x;
}
else
{
y->Parent->right=x;
}
if (y!=curr)
{
curr->data=y->data;
}
return y;
}
best regards
Edited by hadas_zr, 31 May 2011 - 03:18 PM.


Sign In
Create Account

Back to top









