void del_x(TNode* p)
{
if(p!=NULL)
{
del_x(p->lchild);
del_x(p->rchild);
free(p);//最後釋放根
}
}
int del_x_Q(TNode* p,char x)
{
Queue Q;
InitQueue(Q);
if(p==NULL)
return 0;
if(p->data==x)
{
del_x(p);
return 0;
}
EnQueue(Q,p);
while(QueueEmpty(Q)!=true)
{
DeQueue(Q,p);
if(p->lchild!=NULL)
{
if(p->lchild->data==x)
{
del_x(p->lchild);
p->lchild=NULL;
}
else
EnQueue(Q,p->lchild);
}
if(p->rchild!=NULL)
{
if(p->rchild->data==x)
{
del_x(p->rchild);
p->rchild=NULL;
}
else
EnQueue(Q,p->rchild);
}
}
}