Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.
Become a Premium Member and unlock a new, free course in leading technologies each month.
void delete_tree (binarytree *t, int x)
{
binarytree temp;
if (!is_empty(*t))
{
if (x == (*t)-> data)
{
if (((*t) -> left == NULL)&&((*t) -> right == NULL))
{
temp = (*t);
(*t) = NULL;
free (temp);
}
if (((*t) -> left != NULL)&&((*t)-> right == NULL))
{
temp = (*t);
(*t) = (*t) -> left;
free (temp);
}
if (((*t)-> left == NULL)&&((*t)-> right != NULL))
{
temp = (*t);
(*t) = (*t) -> right;
free (temp);
}
if (((*t) -> left != NULL)&&((*t) -> right != NULL))
{
temp = (*t)-> right;
while (temp -> left != NULL)
{
temp = (*t) -> left;
}
temp -> left = (*t) ->left;
temp = (*t);
(*t) = (*t) -> right;
free (temp);
}
}
else {
if ( x <= (*t) -> data)
delete_tree(&(*t) -> left, x);
else
delete_tree(&(*t) -> right, x);
}
}
else printf("No data found.\n");
}
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
void delete_tree (binarytree *t, int x)
{
binarytree temp;
if (!is_empty(*t))
{
if (x == (*t)-> data)
{
if (((*t) -> left == NULL)&&((*t) -> right == NULL))
{
temp = (*t);
(*t) = NULL;
free (temp);
// ADD A RETURN
return;
}
if (((*t) -> left != NULL)&&((*t)-> right == NULL))
{
temp = (*t);
(*t) = (*t) -> left;
free (temp);
// ADD A RETURN
return;
}
if (((*t)-> left == NULL)&&((*t)-> right != NULL))
{
temp = (*t);
(*t) = (*t) -> right;
free (temp);
// ADD A RETURN
return;
}
if (((*t) -> left != NULL)&&((*t) -> right != NULL))
{
temp = (*t)-> right;
while (temp -> left != NULL)
{
temp = (*t) -> left;
}
temp -> left = (*t) ->left;
temp = (*t);
(*t) = (*t) -> right;
free (temp);
}
}
else {
if ( x <= (*t) -> data)
delete_tree(&(*t) -> left, x);
else
delete_tree(&(*t) -> right, x);
}
}
else printf("No data found.\n");
}
Orvoid delete_tree (binarytree *t, int x)
{
binarytree temp;
if (!is_empty(*t))
{
if (x == (*t)-> data)
{
if (((*t) -> left == NULL)&&((*t) -> right == NULL))
{
temp = (*t);
(*t) = NULL;
free (temp);
}
// ADD AN ELSE
else if (((*t) -> left != NULL)&&((*t)-> right == NULL))
{
temp = (*t);
(*t) = (*t) -> left;
free (temp);
}
// ADD AN ELSE
else if (((*t)-> left == NULL)&&((*t)-> right != NULL))
{
temp = (*t);
(*t) = (*t) -> right;
free (temp);
}
// ADD AN ELSE
else if (((*t) -> left != NULL)&&((*t) -> right != NULL))
{
temp = (*t)-> right;
while (temp -> left != NULL)
{
temp = (*t) -> left;
}
temp -> left = (*t) ->left;
temp = (*t);
(*t) = (*t) -> right;
free (temp);
}
}
else {
if ( x <= (*t) -> data)
delete_tree(&(*t) -> left, x);
else
delete_tree(&(*t) -> right, x);
}
}
else printf("No data found.\n");
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.