扩展二叉树
来源:互联网 发布:淘宝如何部分商品退款 编辑:程序博客网 时间:2024/06/05 18:17
Problem Description
由于先序、中序和后序序列中的任一个都不能唯一确定一棵二叉树,所以对二叉树做如下处理,将二叉树的空结点用·补齐,我们把这样处理后的二叉树称为原二叉树的扩展二叉树,扩展二叉树的先序和后序序列能唯一确定其二叉树。现给出扩展二叉树的先序序列,要求输出其中序和后序序列。
Input
输入有多组数据,对于每组数据就一行为扩展二叉树序列(序列长度不超过50)。
Output
对于每组输入输出两行,分别是该二叉树的中序和后序序列。
Sample Input
ABD..EF..G..C..
Sample Output
DBFEGACDFGEBCA
//解题报告:二叉树的建立与遍历。
//标程:
#include<stdio.h>#include<string.h>#include<malloc.h>typedef struct btnode {char data;struct btnode *lchild,*rchild;}NODE;char s[100];int i;NODE *creat(NODE *p){NODE *t;if(s[++i]=='.') p=NULL;else {p->data=s[i];t=(NODE *) malloc (sizeof(NODE));p->lchild=creat(t);t=(NODE *) malloc (sizeof(NODE));p->rchild=creat(t);}return p;}void inorder(NODE *root){if(root!=NULL){inorder(root->lchild);printf("%c",root->data);inorder(root->rchild);}return ;}void postorder(NODE *root){ if(root!=NULL) { postorder(root->lchild); postorder(root->rchild); printf("%c",root->data); } return ;}int main(){ //freopen("a.txt","r",stdin);while(scanf("%s",s)!=EOF){i=-1; NODE *root,*q,n; q=&n;root=creat(q);inorder(root);printf("\n");postorder(root);printf("\n");}return 0;}
- 扩展二叉树
- 扩展二叉树
- 扩展二叉树(树)
- 3.10分层遍历二叉树-扩展问题
- 二叉树的建立(扩展二叉树法)
- 使用扩展二叉树的方法建立二叉树
- AVL平衡树 - 二叉搜索树的扩展1
- 伸展树 - 二叉搜索树的扩展2
- 编程之美-重建二叉树扩展问题1 2
- 3.10 分层遍历二叉树 扩展问题一、二
- 3.10 分层遍历二叉树 扩展问题一、二
- 编程之美 3.9 重建二叉树 扩展问题
- 《数据结构》第五章 树和二叉树 扩展二叉实现代码示例
- 【暂无】 二叉树 扩展二叉树(add-tree.cpp)
- 剑指Offer--039-平衡二叉树(判断一棵二叉树是否是平衡二叉树)[扩展附加题]
- 根据扩展二叉树前序序列生成二叉树,输入某个节点的值,查找其双亲节点的值(二叉链表)
- 树——从最下层向上打印二叉树(层序遍历扩展)
- 二叉树扩展之三叉树C++类模板的实现
- 项目日志
- Spring学习笔记三之IOC(annotation实现)
- 对<Java面试宝典2013版(超长版)>的38个问题的修改
- Ubuntu配置eclipse桌面图标
- 开启关闭休眠功能
- 扩展二叉树
- webservice(四) 发布webservice服务和客户端调用的方式汇总
- Exercise 4.6
- Box2d的基础知识
- OpenCV2 cookbook source code analyse - histogram
- 重建二叉树
- 让人感动的文章
- 【九度】题目1373:整数中1出现的次数(从1到n整数中1出现的次数)
- GCC