数据结构树的相关操作

数据结构树的相关操作

ID:39579082

大小:59.50 KB

页数:3页

时间:2019-07-06

数据结构树的相关操作_第1页
数据结构树的相关操作_第2页
数据结构树的相关操作_第3页
资源描述:

《数据结构树的相关操作》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、/*递归方法相关操作*/#include#definemaxsize100#includetypedefchardatatype;typedefstructnode{datatypedata;structnode*lchild,*rchild;}bitree;/*建立*/bitree*Q[maxsize];bitree*creatree(){charch;intfront,rear;bitree*root,*s;root=NULL;front=1;rear=0;ch=getchar();while(ch!='#'){s=NULL;if(ch!='@

2、'){s=malloc(sizeof(bitree));s->data=ch;s->lchild=NULL;s->rchild=NULL;}rear++;Q[rear]=s;if(rear==1)root=s;else{if(s&&Q[front])if(rear%2==0)Q[front]->lchild=s;elseQ[front]->rchild=s;if(rear%2==1)front++;}ch=getchar();}returnroot;}/*前序遍历*/voidpreorder(bitree*t){if(t){printf("%c",t->data);preorder(t

3、->lchild);preorder(t->rchild);}}/*中序遍历*/voidinorder(bitree*t){if(t){inorder(t->lchild);printf("%c",t->data);inorder(t->rchild);}}/*后序遍历*/voidpostorder(bitree*t){if(t){postorder(t->lchild);postorder(t->rchild);printf("%c",t->data);}}voidmain(){bitree*t;printf("Pleaseinputyourtree:");t=creatree(

4、);printf("");printf("preorder:");preorder(t);printf("");printf("inorder:");inorder(t);printf("");printf("postorder:");postorder(t);getch();}运行结果:

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

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

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