实验4 按照满二叉树的特点生成一棵二叉树
来源:互联网 发布:知豆电动汽车怎么样 编辑:程序博客网 时间:2024/06/06 19:59
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream>#define MAXSIZE 100typedef struct tnode{char data;struct tnode *lchild, *rchild;}tnode,*bitree;int createBiTree(bitree &T,char s[],int n){ if(s[n-1]=='#'){T=NULL; return 0;} else{if(n>strlen(s)){T=NULL;return 0;}else{T=(bitree)malloc(sizeof(tnode)); T->data=s[n-1]; createBiTree(T->lchild,s,2*n); createBiTree(T->rchild,s,2*n+1);}}return 0;}void preorder(bitree T){if(T!=NULL){printf(" %c",T->data); preorder(T->lchild); preorder(T->rchild);}}void inorder(bitree T){ if(T!=NULL){ inorder(T->lchild); printf(" %c",T->data); inorder(T->rchild);}}void postorder(bitree T){ if(T!=NULL){ postorder(T->lchild); postorder(T->rchild); printf(" %c",T->data);}}int main(){bitree h;char s[MAXSIZE];printf("创建的二叉树为:\n");scanf("%s",s); createBiTree(h,s,1);printf("先序遍历的二叉树:\n"); preorder(h); printf("\n"); printf("中序遍历的二叉树:\n"); inorder(h); printf("\n"); printf("后序遍历的二叉树:\n"); postorder(h); printf("\n");return 0;}
阅读全文
0 0
- 实验4 按照满二叉树的特点生成一棵二叉树
- 完全二叉树的特点
- 构建一棵二叉树并按照层次遍历输出
- 按照之字形打印二叉树的节点
- 按照层次遍历二叉树
- 按照层次打印二叉树
- 按照之字形打印二叉树
- 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- SDUT数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- SDUT3340数据结构实验之二叉树一:树的同构
- SDUT数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- OJ3340数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- 从零开始的数据仓库学习生活
- Simulink视频和图像处理模块介绍
- Android依赖库版本不一致
- 装系统
- vue2-学习笔记之高仿饿了吗项目
- 实验4 按照满二叉树的特点生成一棵二叉树
- selenium爬虫and自动化测试
- Ubuntu14.04+QT3.0.1+opencv3.0.0alpha的人脸检测
- PAT Basic 1027
- Java基础知识梳理--线程
- mysql的查询、子查询及连接查询
- Linux系统LCD驱动架构分析
- Python爬虫学习纪要(八):Requests 库学习笔记3
- codeforces 894B