freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

實(shí)驗(yàn)四-平衡二叉樹(shù)演示-資料下載頁(yè)

2025-08-05 04:14本頁(yè)面
  

【正文】 //switch }//if }//else }//else return 1。}/**/includeint DeleteTree(AVLamp。 t,Type e,intamp。 shorter){//平衡二叉樹(shù)的結(jié)點(diǎn)刪除 if(t==NULL){//不存在該元素 return 0。//刪除失敗 } else if(==t){//找到元素結(jié)點(diǎn) AVL q=NULL。 if(tlchild==NULL){//左子樹(shù)為空 q=t。 t=trchild。 delete q。 shorter=1。 } else if(trchild==NULL){//右子樹(shù)為空 q=t。 t=tlchild。 delete q。 shorter=1。 } else{//左右子樹(shù)都存在 q=tlchild。 while(qrchild){//找到要?jiǎng)h除結(jié)點(diǎn)t的左孩子的最右孩子q q=qrchild。 } t=q。//把q的值給t DeleteTree(tlchild,qdata,shorter)。//在左子樹(shù)中遞歸刪除前驅(qū)結(jié)點(diǎn)。即查找q的值 if(shorter){ switch(tbf){ case LH: tbf=EH。 shorter=1。 break。 case EH: tbf=RH。 shorter=0。 break。 case RH: if(trchildbf==EH) shorter=0。 else shorter=1。 RightBalance(t)。//右平衡處理 break。 } } } } else if(t){//左子樹(shù)中繼續(xù)查找 if(!DeleteTree(tlchild,e,shorter)){ return 0。 } if(shorter){ switch(tbf){ case LH: tbf=EH。 shorter=1。 break。 case EH: tbf=RH。 shorter=0。 break。 case RH: if(trchildbf==EH) shorter=0。 else shorter=1。 RightBalance(t)。//右平衡處理 break。 } } } else{//右子樹(shù)中繼續(xù)查找 if(!DeleteTree(trchild,e,shorter)){ return 0。 } if(shorter){ switch(tbf){ case LH: if(tlchildbf==EH) shorter=0。 else shorter=1。 LeftBalance(t)。 //左平衡處理 break。 case EH: tbf=LH。 shorter=0。 break。 case RH: tbf=EH。 shorter=1。 break。 } } } return 1。}/**/includeint DestroyTree(AVLamp。 t){//遞歸銷(xiāo)毀二叉平衡樹(shù) if(t==NULL){ return 0。 } DestroyTree(tlchild)。 DestroyTree(trchild)。 free(t)。 return 1。}/**/includeint InitL(Linkamp。 l){//創(chuàng)建含一個(gè)空頭結(jié)點(diǎn)的雙向鏈表 if(!(l=(Link)malloc(sizeof(LNode))))return 0。 lprior=lnext=NULL。 lt=NULL。 return 1。}int InsertL(Linkamp。 l,AVLamp。 t,char* name){//在雙向鏈表中插入元素 Link p。 p=(Link)malloc(sizeof(LNode))。 pt=t。 strcpy(ptree_name,name)。//將平衡樹(shù)的樹(shù)名保存 pnext=lnext。 if(lnext!=NULL)lnextprior=p。 lnext=p。 pprior=l。 return 1。}const int SearchL(Link l,char* name,Linkamp。 s){//在鏈表中查詢(xún)樹(shù)名,成功則獲取該鏈表結(jié)點(diǎn)的地址,返回true l=lnext。 while(l!=NULL){ if(strcmp(ltree_name,name)==0){ s=l。 return 1。 } l=lnext。 } return 0。}int DeleteL(Linkamp。 l){//在鏈表中刪除l結(jié)點(diǎn) if(lnext==NULL){ lpriornext=NULL。 free(l)。 } else{ lpriornext=lnext。 lnextprior=lprior。 free(l)。 } return 1。}/**/includeint MergeTree(AVLamp。 t1,AVLamp。 t2){//將樹(shù)t2合并到t1上 while(t2!=NULL){ int taller,shorter。 InsertTree(t1,t2data,taller)。 DeleteTree(t2,t2data,shorter)。 } return 1。}/**/includeconst int PrintTreeStructure(AVL t){//利用層次遍歷,輸出樹(shù)的形狀 if(!t){return 0。} int i=0,level=0,j,num。 LinkQ q。 InitQ(q)。 while(1){ i++。 num=0。 j=1。 while(j=i){ num++。//num為記層標(biāo)志,記錄當(dāng)前T所在層數(shù) j=2*j。 } if(t!=NULL){ coutt(tbf) 。 EnQ(q,tlchild)。 EnQ(q,trchild)。 if(j==i+1){ coutendl。 } if(tlchild==NULLamp。amp。trchild==NULL){//T為空時(shí)進(jìn)行判斷,當(dāng)平衡樹(shù)中出現(xiàn)層數(shù)不同的空結(jié)點(diǎn)時(shí),終止輸出 if(!level){//首次出現(xiàn)兩個(gè)孩子都空的結(jié)點(diǎn),將其孩子的層數(shù)賦給level level=num+1。 } } } else{ EnQ(q,NULL)。//若該點(diǎn)為空,則它的孩子也為空,入隊(duì)列 EnQ(q,NULL)。 if(levelamp。amp。level+2==num){ return 1。 } else{cout* 。}//用*代表空 if(j==i+1){ coutendl。 } } DeQ(q,t)。 }//while}/**/include int InitQ(LinkQamp。 q){//創(chuàng)建空隊(duì)列 ==(QP)malloc(sizeof(QNode))。 if(!)return 0。 next=NULL。 return 1。}int EnQ(LinkQamp。 q,AVL e){//入隊(duì)列 QP p。 p=(QP)malloc(sizeof(QNode))。 if(!p)return 0。 ptree=e。 pnext=NULL。 next=p。 =p。 return 1。}int DeQ(LinkQamp。 q,AVLamp。 e){//出隊(duì)列 if(==)return 0。 QP p。 p=next。 e=ptree。 next=pnext。 if(==p)=。 free(p)。 return 1。}/**/includevoid R_Rotate(AVLamp。 t){//以T為根節(jié)點(diǎn)的二叉排序樹(shù)進(jìn)行右旋轉(zhuǎn) AVL l。 l=tlchild。 tlchild=lrchild。 lrchild=t。 t=l。//p指向新的根節(jié)點(diǎn)}void L_Rotate(AVLamp。 t){//以T為根節(jié)點(diǎn)的二叉排序樹(shù)進(jìn)行左旋轉(zhuǎn) AVL r。 r=trchild。 trchild=rlchild。 rlchild=t。 t=r。}/**/includeconst int SearchTree(AVL t,Type key,AVLamp。 p){//搜索樹(shù)中是否包含該元素 while(t){ if(==t){p=t。return 1。} e
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評(píng)公示相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1