- JD *delnode(JD *r,JD *p,JD *f)
- { JD *q,*s;
- int flag=0;
- if(p->lchild==NULL) s=p->rchild;
- else if(p->rchild==NULL) s=p->lchild;
- else{ q=p;
- s=p->lchild;
- while(s->rchild!=NULL)
- { q=s;
- s=s->rchild;
- }
- if(q==p) q->lchild=s->lchild;
- else q->rchild=s->lchild;
- p->data=s->data;
- free(s);
- flag=1;
- }
- if(flag==0)
- { if(f==NULL) r=s;
- else if(f->lchild==p) f->lchild=s;
- else f->rchild=s;
- free(p);
- }
- return(r);
- }