Page 135 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 135
Advanced Data Structure and Algorithms
Notes temp = x->lchild;
y->lchild = x->lchild;
while(temp->rchild != NULL)
temp = temp->rchild;
temp->rchild=x->rchild;
x->lchild=NULL;
x->rchild=NULL;
}
else
{
temp = x->rchild;
y->rchild = x->rchild;
while(temp->lchild != NULL)
temp = temp->lchild;
temp->lchild=x->lchild;
x->lchild=NULL;
x->rchild=NULL;
}
free(x);
return(p);
}
/* this code is for deleting a node with on child*/
if(x->lchild == NULL && x->rchild !== NULL)
{
if(y->lchild == x)
y->lchild = x->rchild;
else
y->rchild = x->rchild;
x->rchild; = NULL;
free(x);
return(p);
}
if( x->lchild != NULL && x->rchild == NULL)
{
if(y->lchild == x)
y->lchild = x->lchild ;
else
y->rchild = x->lchild;
x->lchild = NULL;
free(x);
130 LOVELY PROFESSIONAL UNIVERSITY