91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

胡學剛版數據結構實驗3代碼 合工大,能直接運行。CPP文件

資源截圖

代碼片段和文件信息



#include?

using?namespace?std;
#define?RIGHT?1
#define?LEFT?-1
#define?ROOT?0
#define?MAX?59
#define?HEADSPACE?20

typedef?char?elementtype;

class?tree
{
public:
tree(){father=NULL;lchild=NULL;rchild=NULL;self=this;};//初始化
tree*?getfather()const{return?father;};//獲取父結點指針
tree*?getlchild()const{return?lchild;};//獲取左孩子結點指針
tree*?getrchild()const{return?rchild;};//獲取右孩子結點指針
tree*?getself()const{if(this!=NULL)return?self;else?return?NULL;};//獲取自身指針;
elementtype?getdata()const{return?data;};//獲取結點值
bool?empty()const{return?lchild==NULL&&rchild==NULL&&data==‘\0‘;};//判斷樹是否為空
bool?intree(tree?*add)const;//判斷結點是否在樹內
bool?setdata(elementtype?da){data=da;return?true;};//設置結點值
bool?setfather(tree?*add){father=add;return?true;};//設置父結點指針
bool?setlchild(tree?*add){deletelchild();lchild=add;if(getlchild()!=NULL)getlchild()->setfather(getself());return?true;};//設置左孩子指針
bool?setrchild(tree?*add){deleterchild();rchild=add;if(getrchild()!=NULL)getrchild()->setfather(getself());return?true;};//設置右孩子指針
bool?resetlchild(tree?*add){lchild=add;if(getlchild()!=NULL)getlchild()->setfather(getself());return?true;}//重設左孩子指針
bool?resetrchild(tree?*add){rchild=add;if(getrchild()!=NULL)getrchild()->setfather(getself());return?true;}//重設右孩子指針
bool?getadd(elementtype?datree?*&add)const;//按值查找結點
bool?insertlchild(tree?*add);//插入左子樹
bool?insertrchild(tree?*add);//插入右子樹
bool?deletelchild();//刪除左子樹
bool?deleterchild();//刪除右子樹
bool?deleteself();//刪除整棵樹
int?gettype()const;//獲取結點是什么類型的孩子?根,左孩子,右孩子
int?getfrool()const;//獲取結點的層數
bool?gethigh(int?&n)const;//獲取樹高

private:
tree?*father*lchild*rchild*self;
elementtype?data;
};

bool?tree::intree(tree?*add)const
{
if(empty()&&add==NULL)
return?true;
tree?*p=add;
while(p!=NULL&&p!=self)
p=p->getfather();
if(p==self)
return?true;
else
return?false;
}

bool?tree::insertlchild(tree?*add)
{
if(add->getfather()!=NULL)
{
if(add->gettype()==RIGHT)
add->getfather()->setrchild(NULL);
else
add->getfather()->setlchild(NULL);
}
if(lchild!=NULL)
return?false;
lchild=add;
add->setfather(getself());
return?true;
}

bool?tree::insertrchild(tree?*add)
{
if(add->getfather()!=NULL)
{
if(add->gettype()==RIGHT)
add->getfather()->setrchild(NULL);
else
add->getfather()->setlchild(NULL);
}
if(rchild!=NULL)
return?false;
rchild=add;
add->setfather(getself());
return?true;
}

bool?tree::getadd(elementtype?datree?*&add)const
{
tree?*p=getself();
if(p!=NULL)
{
if(p->data==da)
{
add=p;
return?true;
}
return?(p->getlchild()->getadd(daadd))||(p->getrchild()->getadd(daadd));
}
else
return?false;
}

int?tree::gettype()const
{
if(getfather()==NULL)
{
return?ROOT;
}
else
{
if(self==getfather()->getlchild())
{
return?LEFT;
}
else
return?RIGHT;
}
}

int?tree::getfrool()const
{
int?n=0;
tree?*p=getself();
do{
p=

評論

共有 條評論