33,027
社区成员




typedef struct node
{
int x;
struct node * left;
struct node * right;
}tree;
tree * parent(tree * root, int x)
{
if (!root || root->x == x)
return NULL;
if (root->left && root->left->x == x)
return root;
if (root->right && root->right->x == x)
return root;
return parent(root->left, x) + parent(root->right, x);
}
void del_tree(tree * root)
{
if (!root) return;
if (root->left) del_tree(root->left);
if (root->right) del_tree(root->right);
free(root);
}
void delleft(tree * root, int x)
{
if (root->x == x)
{
del_tree(root->left);
root->left = NULL;
}
if (root->left) delleft(root->left, x);
if (root->right) delleft(root->right, x);
}