推荐回答
#include#include#include#defineNUM_NODE12typedefstructBiTree{intdata;BiTree*lchild;BiTree*rchild;}BiTree;BiTree*CreateTreeintn{BiTree*t;ifnNUM_NODEreturnNULL;if!t=BiTree*mallocsizeofBiTreereturnNULL;t->data=n;printf"%d",t->data;t->lchild=CreateTree2*n;t->rchild=CreateTree2*n+1;returnt;}voidFreeTreeBiTree*t{ift{ift->lchildFreeTreet->lchild;ift->rchildFreeTreet->rchild;printf"%d",t->data;freet;}}typedefstructNodePos{BiTree*pos;intDepth;}NodePos;//前序查找,如果返回0,说明树中没有这个数depth参数为根结点的层数,由用户定intPreSeekBiTree*T,intdata,intdepth,NodePos*p{intret=0;ifT->data==data{p->Depth=depth;p->pos=T;ret=1;}else{ifT->lchildret+=PreSeekT->lchild,data,depth+1,p;ifT->rchildret+=PreSeekT->rchild,data,depth+1,p;}returnret;}intmain{BiTree*root;printf"CreateTree";root=CreateTree1;printf"Inputwhatyoulookingfor:";inta;NodePospos;scanf"%d",&a;ifPreSeekroot,a,1,&posprintf"结点地址为:%8X,深度:%d",pos.pos,pos.Depth;elseprintf"Nodenotfound";printf"FreeTree";FreeTreeroot;return0;。
边可斌2019-12-21 18:57:43
提示您:回答为网友贡献,仅供参考。