数据结构二叉树习题含答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

611AC23A2B3C4D531001A250B500C254D50141025hA11B10C111025D1010245hmk(1=k=h)Amk-1Bmk-1Cmh-1Dmh-16ABCD71AB.C.D.8ABCD9ABCD10ABCD11ABCD12XXXAXBXCXDX13ABCD14ABCD15FBFFnBAn-1BnCn+1Dn+2212ABDFCEGHBFDAGEHC(1)(2)380.070.190.020.060.320.030.210.1081100w={7,19,2,6,32,3,21,10}[2,36],(7,10),,,19,21,321004060192132281711ABFD(CEHGAEDCBHGFAEDCBHGFnull0101011921320101017106012371065231WPL2(0.19+0.32+0.21)+4(0.07+0.06+0.10)+5(0.02+0.03)=1.44+0.92+0.25=2.612WPL3(0.19+0.32+0.21+0.07+0.06+0.10+0.02+0.03)=34ABCDEFG312742811HT:weightparentlchildrchild13000212000370004400052000680007110008000900010000110001200013000weightparentlchildrchild10000.0720010.1930100.0240110.0651000.3261010.03111000.072000.193111100.02411100.065100.3231intLeafNodeCount(BiTreeT){if(T==NULL)return0;//0elseif(T-lchild==NULL&&T-rchild==NULL)return1;//1elsereturnLeafNodeCount(T-lchild)+LeafNodeCount(T-rchild);}23voidChangeLR(BiTree&T){BiTreetemp;if(T-lchild==NULL&&T-rchild==NULL)return;else{temp=T-lchild;T-lchild=T-rchild;T-rchild=temp;13800212120037100044900528006810007111100859519911481015123611201397122713210134701112}ChangeLR(T-lchild);ChangeLR(T-rchild);}4voidDoubleTraverse(BiTreeT){if(T==NULL)return;elseif(T-lchild==NULL&&T-rchild==NULL)coutT-data;else{coutT-data;DoubleTraverse(T-lchild);coutT-data;DoubleTraverse(T-rchild);}}5[]intWidth(BiTreebt)//bt{if(bt==null)return(0);//0else{BiTreeQ[];//Qfront=1;rear=1;last=1;//front,rear,lasttemp=0;maxw=0;//temp,maxwQ[rear]=bt;//while(front=last){p=Q[front++];temp++;//1if(p-lchild!=null)Q[++rear]=p-lchild;//if(p-rchild!=null)Q[++rear]=p-rchild;//if(frontlast)//{last=rear;if(tempmaxw)maxw=temp;//last,temp=0;}//if}//whilereturn(maxw);}//width61intLevel(BiTreebt)//1{intnum=0;//num1if(bt){QueueInit(Q);QueueIn(Q,bt)//Qwhile(!QueueEmpty(Q)){p=QueueOut(Q);printf(p-data);//,if(p-lchild&&!p-rchild||!p-lchild&&p-rchild)num++;//1if(p-lchild)QueueIn(Q,p-lchild);//if(p-rchild)QueueIn(Q,p-rchild);//}}//if(bt)return(num);}//17[]voidLongestPath(BiTreebt)//{BiTreep=bt,l[],s[];//l,slintitop=0,tag[],longest=0;while(p||top0){while(p){s[++top]=ptag[top]=0;p=p-Lc;}//if(tag[top]==1)//{if(!s[top]-Lc&&!s[top]-Rc)//if(toplongest){for(i=1;i=top;i++)l[i]=s[i];longest=top;top--;}//l}elseif(top0){tag[top]=1;p=s[top].Rc;}//}//while(p!=null||top0)}//LongestPath8[]*b*bpathb-datavoidAllPath(BTNode*b,ElemTypepath[],intpathlen){inti;if(b!=NULL){if(b-lchild==NULL&&b-rchild==NULL)//*b{coutb-data:b-data;for(i=pathlen-1;i=0;i--)coutendl;}else{path[pathlen]=b-data;//pathlen++;//1AllPath(b-lchild,path,pathlen);//AllPath(b-rchild,path,pathlen);//pathlen--;//}}}

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功