二叉树转双向链表 和 中缀转二树

二叉树转双向链表 和 中缀转二树

ID:14178607

大小:53.50 KB

页数:9页

时间:2018-07-26

二叉树转双向链表 和 中缀转二树_第1页
二叉树转双向链表 和 中缀转二树_第2页
二叉树转双向链表 和 中缀转二树_第3页
二叉树转双向链表 和 中缀转二树_第4页
二叉树转双向链表 和 中缀转二树_第5页
资源描述:

《二叉树转双向链表 和 中缀转二树》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、#include#include#include#includetypedefcharelemtype;structbnode{elemtypedata;structbnode*lchild,*rchild;};constN=10;structbnode*s[N];inth=-1,r=-1,k=0;structbnode*set_tree(){structbnode*t,*p,*q;inti;chard;t=new(bnode);t->data=rand()%26+'A';t->lchil

2、d=NULL;t->rchild=NULL;for(i=1;ip->data){q=p;p=p->rchild;}else{q=p;p=p->lchild;}p=new(bnode);p->data=d;p->lchild=NULL;p->rchild=NULL;if(d>q->data)q->rchild=p;elseq->lchild=p;}returnt;}voidinq(structbnode*t){if(k!=N*2){r++;s[r]=t;k++;}elseco

3、ut<<"Overflow";}voidpre_order(structbnode*t){if(t!=NULL){cout<data<<"";pre_order(t->lchild);pre_order(t->rchild);}}voidmid_order(structbnode*t){if(t!=NULL){mid_order(t->lchild);cout<data<<"";mid_order(t->rchild);}}voidallinq(structbnode*t)//二叉树中序进队(数组){if(t!=NULL){allinq(t->lch

4、ild);inq(t);allinq(t->rchild);}}structbnode*conver(structbnode*t){inti=0;structbnode*p,*m,*y;allinq(t);y=s[0];y->lchild=NULL;for(i=0;irchild=m;m->lchild=p;}m->rchild=NULL;returny;}voiddisp_doublelink(bnode*h)//显示双向二叉树{cout<<"显示双向链表(转一圈)"<rchi

5、ld!=NULL){cout<data<<"";h=h->rchild;}while(h!=NULL){cout<data<<"";h=h->lchild;}cout<

6、lude#include#include#defineTRUE1#defineFALSE0#defineMAXNUM1000typedefintDataType;structBinTreeNode;typedefstructBinTreeNode*PBinTreeNode;structBinTreeNode{DataTypeinfo;PBinTreeNodellink;PBinTreeNoderlink;};typedefstructBinTreeNode*BinTree;typedefBinTree*PBi

7、nTree;intextoBinTree(PBinTreepbtree,constchar*ex,intn)/*从中缀表达式ex(长度为n)创建二叉树。若是一个合法的表达式,则返回TRUE,且算法结束时*pbtree存放二叉树的根节点的地址;否则返回FALSE*/{charc;intindex,i,bracket;inthave_bracket=FALSE;/*记录表达式中是否包含括号*/intnum,state_int,nint;inttag1,tag2;if(ex[0]==''

8、

9、ex[0]=='t'

10、

11、ex[0]=='')returnextoBinT

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。