//BSNode*maxNode=NULL;
//intmax=Max(pNode->m_lchild,maxNode);
//maxNode->m_rchild=pNode->m_rchild;
//}
}
if(root==NULL)
{
cout<<"删除结点后,二叉排序树为空!"<<endl;
}
else
{
cout<<"结点"<<item<<"删除成功!"<<endl;
}
}
else
{
cout<<"数值为"<<item<<"的结点不存在!"<<endl;
}
}
//求最小值:返回以root为根的树中结点的最小值,结点返回给minNode
intBSTree::MinNode()
{
BSNode*minNode;
returnMin(root,minNode);
}
//求最小值:返回以root为根的树中结点的最小值,结点返回给minNode
intBSTree::Min(BSNode*root,BSNode*&minNode)
{
intmin=0;
BSNode*p=root;
if(p==NULL)
{
cout<<"树空!"<<endl;
return-1;//结果为-1表示树空,最小值不存在
}
else
{
while(p->m_lchild)
{
p=p->m_lchild;
}
minNode=p;
returnminNode->data;
}
returnmin;
}
//求最大值:返回以root为根的树中结点的最大值,结点返回给maxNode
intBSTree::MaxNode()
{
BSNode*maxNode=NULL;
returnMax(root,maxNode);
}
//求最大值:返回以root为根的树中结点的最大值,结点返回给maxNode
intBSTree::Max(BSNode*root,BSNode*&maxNode)
{
intmax=0;
BSNode*p=root;
if(p==NULL)
{
cout<<"树空!"<<endl;
return-1;//结果为-1表示树空,最大值不存在
}
else
{
while(p->m_rchild)
{
p=p->m_rchild;
}
maxNode=p;
returnmaxNode->data;
}
returnmax;
}
//求双亲结点:返回值为item的结点的双亲结点
BSNode*BSTree::GetParent(intitem)
{
returngetParent(root,item);
}
//求双亲结点:返回值为item的结点的双亲结点
BSNode*BSTree::getParent(BSNode*root,intitem)
{
BSNode*pParent=NULL;//指向双亲结点的指针
BSNode*pNode=NULL;
if(Find(root,pNode,item))//找到值为item的结点
{
if((root==NULL)||(root==pNode))//树空,或该结点为根结点,则不存在双亲结点
{
pParent=NULL;
}
else//树不空且该结点不是根结点
{
if(root->m_lchild==pNode||root->m_rchild==pNode)
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25453-5.html
好好听
接下来是应该看我们的了