增强萨满练级天赋:有一道数据结构的问题?

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/27 13:25:19
bool Delete(BSTNode*& BST,const ElemType & item)
{
BSTNode*t=BST,*s=NULL;
while(t!=NULL){
if(item==t->data)break;
else if(item<t->data){
s=t;t=t->left;
}
else{
s=t;t=t->right;
}
}
if(t==NULL)return false;
if(t->left==NULL&&t->right==NULL)
{
if(t==BST)
BST=NULL;
else if(t==s->left)
s->left=NULL;
else
s->right=NULL;
delete t;
}
else if(t->left==NULL||t->right==NULL)
{
if(t==BST){
if(t->left==NULL)
BST=t->right;
else
BST=t->left;
}
else{
if(t==s->left&&t->left!=NULL)
s->left=t->left;
else if(t==s->left&&t->right!=NULL)
s->left=t->right;
else if(t==s->right&&t->left!=NULL)
s->right=t->left;
else if(t==s->right&&t->right!=NULL)
s->right=t->right;
}
delete t;
}
else if(t->left!=NULL&&t->right!=NULL)
{
BSTNode* p=t;
BSTNode* q=t->left;
while(q->right!=NULL)
p=q;
q=q->right;
}

t->data=q->data;
if(p==t)t->left=q->left;
else p->right=q->left;
delete q;
return true;
}

这是一个二叉搜索树的一个算法,可不知道为什么在我调试的时候,一直有错误,请哪位大虾出来指点一下!!!!!

错误信息贴出来看看