hello frends, i m havig a problem with the deletion of node int the tree plz help me to get my code debugged
void delete_node(struct node *temp,int data)
{
struct node *temp2=NULL,*temp3;
if(temp->data==data&&temp->left==NULL&&temp->right==NULL)
{
temp=NULL;
}
else
{
while(temp->data!=data)
{
printf("\n temp = %d",temp->data);
temp2=temp;
if(temp->data<data)
{
temp=temp->right;
}
else
{
temp=temp->left;
}
if(temp==NULL)
break;
}
if(temp!=NULL)
{
if(temp->left==NULL&&temp->right==NULL)
{
if(temp2->data<data)
temp2->right=NULL;
else
temp2->left=NULL;
}
else if(temp->left==NULL||temp->right==NULL)
{
printf("temp2 = %d",temp2->data);
if(temp2->data<data)
{
if(temp->right==NULL)
temp2->right=temp->left;
else
temp2->right=temp->right;
}
else
{
if(temp->right==NULL)
temp2->left=temp->left;
else
temp2->left=temp->right;
}
free(temp);
}
else
{
//search largest left node
temp3=temp->left;
printf("\n temp 3 %d",temp3->data);
while(temp3->right!=NULL)
{
temp3=temp3->right;
printf("\ntemp3 %d",temp3->data);
getch();
}
//replace data of node to be deleted by largest left node
temp->data=temp3->data;
//delete largest left node
delete_node(temp3,temp3->data);
}
}
}
}