ѧ
ѧԺ
ʵ
2017-2018һѧڣ
γƣ
ѧ ţ
ʵ ݽṹʵ ѧ 1614010102 ר ҵ 16-1 һʵĿģ
1. ˳ҷ
2. նֲҷBinSearch()
ʵݣ
1. ˳ҷԱвң 2.öֲҷԲұв 3.Ըв
ʵ豸
Code Blocks Ӳ
ͼ
ġʵ̼ #include
template
ElemType data;
BinTreeNode
leftChild=rightChild=NULL; }
BinTreeNode(ElemType &item, BinTreeNode
data=item;
leftChild=lChild; rightChild=rChild; } };
template
protected:
BinTreeNode
void DestroyHelp(BinTreeNode
int NodeCountHelp(const BinTreeNode
BinTreeNode
void DeleteHelp(BinTreeNode
BinarySortTree();
BinTreeNode
bool GetElem(const BinTreeNode
void InOrder()const;/// void PreOrder()const;/// void PostOrder()const;///
int NodeCount()const;/// int Height()const;///߶
BinTreeNode
bool Insert(const ElemType &e); ///Ԫe
bool Delete(const KeyType &key); ///ɾؼΪeԪ };
template
BinarySortTree
root=NULL; }
template
void BinarySortTree
if(r!=NULL) {
DestoryHelp(r->leftChild); DestoryHelp(r->rightChild);
delete r; r=NULL; } }
template
void BinarySortTree
BinTreeNode
if(p->leftChild==NULL && p->rightChild==NULL) {
delete p; p=NULL; }
else if(p->leftChild==NULL) {
tmpPtr=p;
p=p->rightChild; delete tmpPtr; } else {
tmpF=p;
tmpPtr=p->leftChild;
while(tmpPtr->rightChild!=NULL) {
tmpF=tmpPtr;
tmpPtr=tmpPtr->rightChild; }
p->data=tmpPtr->data;
if(tmpF->rightChild==tmpPtr) {
DeleteHelp(tmpF->rightChild); } else {
DeleteHelp(tmpF->leftChild); } } }
template
void BinarySortTree
if(r!=NULL)