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

正文內(nèi)容

實驗四-平衡二叉樹演示(編輯修改稿)

2025-09-01 04:14 本頁面
 

【文章內(nèi)容簡介】 break。 case RH: tbf=EH。 shorter=1。 break。 } } } return 1。}int MergeTree(AVLamp。 t1,AVLamp。 t2){//將樹t2合并到t1上 while(t2!=NULL){ int taller,shorter。 InsertTree(t1,t2data,taller)。 DeleteTree(t2,t2data,shorter)。 } return 1。}includeconst int PrintTreeStructure(AVL t){//利用層次遍歷,輸出樹的形狀 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為記層標志,記錄當前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為空時進行判斷,當平衡樹中出現(xiàn)層數(shù)不同的空結(jié)點時,終止輸出 if(!level){//首次出現(xiàn)兩個孩子都空的結(jié)點,將其孩子的層數(shù)賦給level level=num+1。 } } } else{ EnQ(q,NULL)。//若該點為空,則它的孩子也為空,入隊列 EnQ(q,NULL)。 if(levelamp。amp。level+2==num){ return 1。 } else{cout* 。}//用*代表空 if(j==i+1){ coutendl。 } } DeQ(q,t)。 }//while}/**/ifndef H_H_INCLUDEDdefine H_H_INCLUDEDincludeincludeincludeincludeiostreamusing namespace std。define NAME_LENGTH 20define LH 1 //樹的左部比右部高1define EH 0 //樹的左右一般高define RH 1 //樹的右部比左部高1typedef struct Type{//數(shù)據(jù)類型結(jié)構(gòu) float num。}Type。/*平衡樹結(jié)構(gòu)聲明*/typedef struct AVLTree{//二叉平衡樹結(jié)構(gòu)體聲明 int bf。//結(jié)點的平衡因子 struct Type data。//結(jié)點數(shù)據(jù) struct AVLTree* lchild,* rchild。//左右孩子}AVLTree,*AVL。/*隊列結(jié)構(gòu)聲明*/typedef struct QNode{//隊列 AVL tree。 struct QNode* next。}QNode,*QP。typedef struct{ QP fron。 QP rear。}LinkQ。/*雙向鏈表結(jié)構(gòu)聲明*/typedef struct LNode{//鏈表 AVL t。 char tree_name[NAME_LENGTH]。 struct LNode* prior,* next。}LNode,*Link。/*雙向鏈表操作函數(shù)聲明*/int InitL(Linkamp。 )。int InsertL(Linkamp。 ,AVLamp。 ,char* )。int DeleteL(Linkamp。 )。const int SearchL(Link ,char* ,Linkamp。 )。/*菜單*/void Menu()。/*隊列操作函數(shù)聲明*/int InitQ(LinkQamp。 )。int EnQ(LinkQamp。 ,AVL )。int DeQ(LinkQamp。 ,AVLamp。 )。/*平衡樹操作函數(shù)聲明*/void R_Rotate(AVLamp。 )。void L_Rotate(AVLamp。 )。void LeftBalance(AVLamp。 )。void RightBalance(AVLamp。 )。int InsertTree(AVLamp。 ,Type ,intamp。 )。int MergeTree(AVLamp。 ,AVLamp。 )。const int SearchTree(AVL ,Type ,AVLamp。 )。const int PrintTreeStructure(AVL )。int DeleteTree(AVLamp。 ,Type ,intamp。 )。int DestroyTree(AVLamp。 )。endif // H_H_INCLUDED/**/includeint main(){ Menu()。 return 1。}/**/includevoid Menu(){ char i[10*NAME_LENGTH],a。 int j。 for(j=0。j10*NAME_LENGTH。j++){i[j]=39。\039。} Link l。 InitL(l)。//創(chuàng)建包含一個空頭結(jié)點的鏈表 while(1){ system(cls)。 cout 平衡二叉樹(AVL樹)的演示endlendl。 cout endl。 cout endl。 cout endl。 cout endl。 cout endl。 cout endl。 cout endlendl。 cout請輸入操作序號(輸入0退出程序):。 (i,10*NAME_LENGTH,39。\n39。)。 if(strlen(i)!=1){continue。} else{ a=i[0]。 if(a==39。039。){ break。 } } switch(a){ case 39。139。:{ system(cls)。 cout請輸入需要創(chuàng)建的平衡樹個數(shù):。 int j,k。 cink。 for(j=0。jk。j++){ cout請輸入第j+1棵平衡樹的樹名(小于20個字符):。 char name[NAME_LENGTH]。 cinname。 cout請輸入元素個數(shù):endl。 int m,n。 cinn。 cout請依次輸入元素:endl。 Type e。 AVL t=NULL。 for(m=0。mn。m++){ cin。 int taller=0。//增高標識,1為增高,0為不增高 InsertTree(t,e,taller)。//生成樹結(jié)點 } InsertL(l,t,name)。//將該平衡樹命名,并接入鏈表 } cout創(chuàng)建成功!endl。 system(pause)。 system(cls)。 break。 } case 39。239。:{ system(cls)。 cout請輸入你想要訪問的樹名:endl。 char name[NAME_LENGTH]。 cinname。 Link s。 if(!SearchL(l,name,s)){ cout未找到該名字的平衡樹!endl。 system(pause)。 system(cls)。 break。 }//未找到該平衡樹,返回菜單 cout請輸入你要查找的數(shù)endl。 Type m。 AVL p。 cin。 if(SearchTree(st,m,p)){ cout 在樹中存在.endl。 } else{cout該樹中不存在這個數(shù)!endl。} system(pause)。 system(cls)。 break。 } case 39。339。:{ system(cls)。 cout請輸入你想要訪問的樹名:endl。 char name[NAME_LENGTH]。 cinname。 Link s。 if(!SearchL(l,name,s)){ cout未找到該名字的平衡樹!endl。 system(pause)。 system(cls)。 break。 } cout請輸入插入元素個數(shù)endl。 int m,n。 cinn。 cout請依次輸入插入元素endl。 Type e。 for(m=0。mn。m++){ cin。 int taller=0。//增高標識,1為增高,0為不增高
點擊復制文檔內(nèi)容
環(huán)評公示相關推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1