Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.
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.