数据结构实验之二叉树四:(先序中序)还原二叉树 (SDUT 3343)
#include <bits/stdc++.h>
using namespace std;
struct node
{
char data;
struct node *lc, *rc;
};
char a[100],b[100];
int n;
struct node *creat(int len, char a[], char b[])
{
if(len == 0) return NULL;
int i;
struct node *root;
root = new node;
root -> data = a[0];
for(i = 0; i < len; i ++)
{
if(a[0] == b[i])
{
break;
}
}
root -> lc = creat(i, a + 1, b);
root -> rc = creat(len - i - 1,a + i + 1, b + i + 1);
return root;
};
int fin(struct node *root)
{
// cout << "yes" << endl;
int d1, d2;
int h = 0;
if(root)
{
d1 = fin(root -> lc);
d2 = fin(root -> rc);
h = max(d1+1,d2+ 1);
}
return h;
}
int main()
{
while(~scanf("%d",&n))
{
scanf("%s %s", a,b);
struct node *root;
root = creat(n,a,b);
int ans = fin(root);
printf("%d\n",ans);
}
return 0;
}
数据结构实验之二叉树四:(先序中序)还原二叉树 (SDUT 3343)的更多相关文章
- 数据结构实验之链表四:有序链表的归并(SDUT 2119)
#include <bits/stdc++.h> using namespace std; struct node { int data; struct node *next; }; st ...
- SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树
数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...
- SDUT-3343_数据结构实验之二叉树四:(先序中序)还原二叉树
数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定一棵二叉树的先序遍历 ...
- SDUT OJ 数据结构实验之二叉树八:(中序后序)求二叉树的深度
数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Probl ...
- SDUT-2804_数据结构实验之二叉树八:(中序后序)求二叉树的深度
数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 已知一颗二叉树的中序 ...
- Java实现二叉树的前序、中序、后序遍历(非递归方法)
在上一篇博客中,实现了Java中二叉树的三种遍历方式的递归实现,接下来,在此实现Java中非递归实现二叉树的前序.中序.后序遍历,在非递归实现中,借助了栈来帮助实现遍历.前序和中序比较类似,也简单 ...
- Java实现二叉树的前序、中序、后序、层序遍历(非递归方法)
在上一篇博客中,实现了Java中二叉树的四种遍历方式的递归实现,接下来,在此实现Java中非递归实现二叉树的前序.中序.后序.层序遍历,在非递归实现中,借助了栈来帮助实现遍历.前序和中序比较类似, ...
- SDUT OJ 数据结构实验之图论四:迷宫探索
数据结构实验之图论四:迷宫探索 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之排序四:寻找大富翁
数据结构实验之排序四:寻找大富翁 Time Limit: 200 ms Memory Limit: 512 KiB Submit Statistic Discuss Problem Descripti ...
- SDUT 3401 数据结构实验之排序四:寻找大富翁.!
数据结构实验之排序四:寻找大富翁 Time Limit: 150MS Memory Limit: 512KB Submit Statistic Problem Description 2015胡润全球 ...
随机推荐
- Foxmail7.2的账号密码的备份与恢复
1:备份: 1.0 找到Foxmail7.2的安装的位置,例如我的就是 D:\Program Files\Foxmail 7.2; 然后在路径下找到Storage文件夹然后备份里边的内容; 邮箱账号备 ...
- C# Entity Framework The ObjectContext instance has been disposed and can no longer be used for operations that require a connection
The ObjectContext instance has been disposed and can no longer be used for operations that require a ...
- (六)mybatis之多对一关系(简单)
一.需求分析 需求: 查询所有订单信息及订单下的订单明细信息 分析: 一条订单只能由一个消费者下单,但是一条订单有多条订单明细. 二.创建数据库表和实体对象 Customer.java ...
- UnityC#中修改RectTransform
1.改变RectTransform的Left和Buttom GetComponent<RectTransform>().offsetMax = new Vector2(left, top) ...
- 如何让某些用户对Marketing Cloud的contact数据只能实施只读操作
打开maintain business role这个应用: 创建一个新的business role,然后添加下列这几个catalogs: SAP_CEC_BC_MKT_ADM_PC Marketing ...
- dubbo常见异常及解决方式
1.出现RpcException: Failed to invoke the method post in the service com.xxx.xxx.xxx异常怎么办?表示调用失败1.检查网络是 ...
- c语言的函数指针和函数指针数组的简单demo
今天,简单记录一下,函数指针和函数指针数组的使用,废话不多说,直接贴上代码,里面有详细的注释,方便以后查阅. #include <cstdio> #include <Windows. ...
- 论文笔记:Deformable ConvNets v2: More Deformable, Better Results
概要 MSRA在目标检测方向Beyond Regular Grid的方向上越走越远,又一篇大作推出,相比前作DCN v1在COCO上直接涨了超过5个点,简直不要太疯狂.文章的主要内容可大致归纳如下: ...
- Thymeleaf整合到Spring Security,标签sec不起作用
将 pom 文件中的 thymeleaf-extras-springsecurity4 依赖改成 thymeleaf-extras-springsecurity5 <dependency> ...
- python-----批量操作xml文件(新建、增、删、改、查)
最近需要处理xml文件,学习并整理了一些常用的操作,代码如下: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/7/9 15: ...