欢迎来到天天文库
浏览记录
ID:52715500
大小:52.00 KB
页数:2页
时间:2020-03-29
《实验-二叉链表.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验报告4班级:数学091姓名:陈浩学号:200912010220编成实现:二叉树采用二叉链表存储,要求建立一颗二叉树,并输出要求的树状形式与节点编号程序代码如下:#include#include#include#if1typedefstructNode{intnum;chardata;structNode*LChild;structNode*RChild;}BiTNode,*BiTree;voidCreateBiTree(BiTree*bt){charch;ch=getchar();if(ch=='.')*bt=NULL;e
2、lse{*bt=(BiTree)malloc(sizeof(BiTNode));(*bt)->data=ch;CreateBiTree(&((*bt)->LChild));CreateBiTree(&((*bt)->RChild));}}voidPostOrder(BiTreeroot){if(root!=NULL){PostOrder(root->LChild);PostOrder(root->RChild);scanf("%d",&(root->num));}}intPrintTree(BiTreebt,intnLayer,intflag){inti;if(bt==NULL)re
3、turn1;PrintTree(bt->RChild,nLayer+1,flag);for(i=0;idata);elseprintf("%d",bt->num);PrintTree(bt->LChild,nLayer+1,flag);return0;}voidmain(){voidCreateBiTree(BiTree*bt);intPrintTree(BiTreebt,intnLayer,intflag);voidPostOrder(BiTreeroot);BiTreebt
4、=NULL;printf("inputthedataoftheNode:");CreateBiTree(&bt);PrintTree(bt,1,1);printf("inputthenumoftheNode:from1ton(nisthenumberofthenode):");PostOrder(bt);PrintTree(bt,1,0);}#endif运行结果:
此文档下载收益归作者所有