数据结构上机测试4.1:二叉树的遍历与应用1
来源:互联网 发布:阿里云邮箱登陆入口 编辑:程序博客网 时间:2024/05/23 13:55
数据结构上机测试4.1:二叉树的遍历与应用1
Time Limit: 1000MS Memory limit: 65536K
题目描述
输入二叉树的先序遍历序列和中序遍历序列,输出该二叉树的后序遍历序列。
输入
第一行输入二叉树的先序遍历序列;
第二行输入二叉树的中序遍历序列。
第二行输入二叉树的中序遍历序列。
输出
输出该二叉树的后序遍历序列。
示例输入
ABDCEFBDAECF
示例输出
DBEFCA
#include<stdio.h>#include<string.h>#include<malloc.h>#include<stdlib.h>typedef struct node{ char data; struct node *lchild,*rchild;}*Tree;void CreateBitree(Tree &p){ char ch; scanf("%c",&ch); if(ch==',') p=NULL; else { p=new node; p->data=ch; CreateBitree(p->lchild); CreateBitree(p->rchild); } return ;}void zpreorder(Tree p){ if(p) { zpreorder(p->lchild); printf("%c",p->data); zpreorder(p->rchild); }}void hpreorder(Tree p){ if(p) { hpreorder(p->lchild); hpreorder(p->rchild); printf("%c",p->data); }}void ycount(Tree p,int &count){ if(p) { if(p->lchild==NULL&&p->rchild==NULL) { count++; return ; } if(p->lchild) ycount(p->lchild,count); if(p->rchild) ycount(p->rchild,count); }}int sleaf(Tree p){ int high=0; if(!p) return high; int n=sleaf(p->lchild); int m=sleaf(p->rchild); high=m>n?m:n; return high+1;}int main(){ node *p; CreateBitree(p); zpreorder(p); printf("\n"); hpreorder(p); printf("\n"); int countleaf=0; ycount(p,countleaf); printf("%d\n",countleaf); printf("%d\n",sleaf(p)); return 0;}
0 0
- 数据结构上机测试4.1:二叉树的遍历与应用
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 1291 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 【1291】数据结构上机测试4.1:二叉树的遍历与应用1 SDUTOJ
- 1291 数据结构上机测试4.1:二叉树的遍历与应用1
- SDUTOJ 1291 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1--知先序和中序求后序
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1 (*详解
- 数据结构上机测试4.1:二叉树的遍历与应用1
- 数据结构上机测试4.1:二叉树的遍历与应用1
- zookeeper机制原理
- 求二叉树的先序遍历
- warning C4996: “fopen”被声明为否决的
- 汇编语言转移指令规则汇总
- 数据结构上机测试4.1:二叉树的遍历与应用1
- SVN 版本恢复命令行操作
- LeetCode 4 — Median of Two Sorted Arrays (C++ Java Python)
- C#使用比较操作符(!=、<、>、<=、>=)的字符串构造Lambda表达式树,并生成委托执行
- JQuery 选择器及radio,checkbox,select取值
- js 表格排序(编辑+拖拽+缩放)
- 美国Ivanpah太阳能发电站:飞经这里的鸟都被烧焦了
- TEST
- Dubbo基本原理机制