3340 数据结构实验之二叉树一:树的同构
来源:互联网 发布:软件企业认定有效期 编辑:程序博客网 时间:2024/05/29 14:22
数据结构实验之二叉树一:树的同构
#include<bits/stdc++.h> using namespace std; struct tree { char c; struct tree *lc,*rc; }; struct node { char s; int l,r; } a[15]; struct tree * creat(int k) { struct tree *t; t=(struct tree *)malloc(sizeof(struct tree)); t->lc=t->rc=NULL; t->c=a[k].s; if(a[k].l!=-1) t->lc=creat(a[k].l); if(a[k].r!=-1) t->rc=creat(a[k].r); return t; }; struct tree *build(int n) { int j; bool v[15]; memset(v,false,sizeof(v)); for(int i=0; i<n; i++) { char s1[10],s2[10],s3[10]; scanf("%s%s%s",s1,s2,s3); a[i].s=s1[0]; if(s2[0]=='-') a[i].l=-1; else { a[i].l=s2[0]-'0'; v[a[i].l]=true; } if(s3[0]=='-') a[i].r=-1; else { a[i].r=s3[0]-'0'; v[a[i].r]=true; } } if(n!=0) { for(j=0; j<n; j++) if(!v[j]) break; } struct tree *root1=creat(j); return root1; }; int ju(struct tree *t1,struct tree *t2) { if(t1==NULL&&t2==NULL) return 1; if(t1!=NULL&&t2!=NULL) if(t1->c==t2->c) if((ju(t1->lc,t2->lc)&&ju(t1->rc,t2->rc))||(ju(t1->rc,t2->lc)&&ju(t1->lc,t2->rc))) return 1; return 0; } int main() { int n; while(~scanf("%d",&n)) { struct tree *root1=build(n); int m; scanf("%d",&m); struct tree *root2=build(m); if(ju(root1,root2)) printf("Yes\n"); else printf("No\n"); } }
0 0
- 3340数据结构实验之二叉树一:树的同构
- 3340 数据结构实验之二叉树一:树的同构
- 3340-->数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- SDUT数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- SDUT3340数据结构实验之二叉树一:树的同构
- SDUT数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- OJ3340数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- SDUT 数据结构实验之二叉树一:树的同构
- 数据结构实验之二叉树一:树的同构
- python ddt 数据驱动测试
- 数据结构——树的概述
- Memcached 与 Redis 实现的对比(下)
- springMVC请求流程详解
- TCP Nagel算法
- 3340 数据结构实验之二叉树一:树的同构
- C# 第十一章上机练习1
- android-多渠道自动打包之一秒五包
- iOS一行代码调用手机系统震动
- 面向对象的设计思想
- MySQL日期时间函数大全
- Slow performance occurs when you copy data to a TCP server by using a Windows Sockets API program
- 第十三周项目3-Dijkstra算法的验证
- git分支管理