数据结构上机测试4.1:二叉树的遍历与应用1
2017-02-07 12:10
561 查看
Problem Description
输入二叉树的先序遍历序列和中序遍历序列,输出该二叉树的后序遍历序列。Input
第一行输入二叉树的先序遍历序列;第二行输入二叉树的中序遍历序列。
Output
输出该二叉树的后序遍历序列。Example Input
ABDCEF BDAECF
Example Output
DBEFCA
#include<stdio.h> #include<string.h> #include<stdlib.h> typedef struct node { char data; struct node *lc,*rc; }bitree; bitree * create(int hlen,char qst[51],char hst[51]) { int i; bitree * t; if(hlen<=0) return NULL; t=(bitree *)malloc(sizeof(bitree)); t->data=qst[0]; for(i=0;i<hlen;i++) { if(hst[i]==qst[0]) break; } t->lc=create(i,qst+1,hst); t->rc=create(hlen-i-1,qst+i+1,hst+i+1); return t; } void postshow(bitree * tree) { bitree * t; t=tree; if(t) { postshow(t->lc); postshow(t->rc); printf("%c",t->data); } } int main() { int hlen; char qst[51],hst[51]; bitree * tree; scanf("%s%s",qst,hst); hlen=strlen(hst); tree=create(hlen,qst,hst); postshow(tree); printf("\n"); return 0; }
相关文章推荐
- 数据结构上机测试4.1:二叉树的遍历与应用1【根据二叉树的前序序列和中序序列求后序序列方法1,2】
- 数据结构上机测试4.1:二叉树的遍历与应用1
- SDUTOJ 1291 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- sdutacm-数据结构上机测试4.1:二叉树的遍历与应用1
- 【1291】数据结构上机测试4.1:二叉树的遍历与应用1 SDUTOJ
- 【1291】数据结构上机测试4.1:二叉树的遍历与应用1 SDUTOJ
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- C语言 数据结构之二叉树 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1 oj
- 1489 求二叉树的先序遍历 1291 数据结构上机测试4.1:二叉树的遍历与应用1【二叉树遍历顺序转换】
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1 (*详解
- SDUT 1291数据结构上机测试4.1:二叉树的遍历与应用1