550 Programming and Data Structures
search (ole,&father,&position);
if(positian=*0)
{
prin tf ("Item dose not exist in tree") ;
return 0;
}
i f (position->ls=*0 && position- >rs=*0)
a (father, position);
i f (position- >lsI«0 && position->rs=«0)
b (father, position);
i f (position->ls*«0 && position->rs! »0)
b(father,position);
i f (position->ls 1*0 && position->rsl-0)
c(father,position) ;
free (position);
return 0;
}
a (struct b tree *p_r, struct b tree *l_c )
{
if(p _r»«0 ) r_node-0;
else if(l_c*ep_r->ls)
p _r->ls»0;
else p_r->rs«0;
return 0;
}
b (struct b tree *p_r, struct b tree *1 c)
struct b_tree *child;
i f (l_c->ls!»0) child»l_c->ls;
else child=l_c->rs;
i f (p_r«»0 ) r_node»child;
else
i f ( l_c««p_r-> ls)
Pjr->ls«child;
else p_r->rs»child;
return 0;
c (struct b tree ♦p r, struct b tree *1 c)
{
struct b tree *pstr,*p save,*sue,*parsue;