#include<bits/stdc++.h>
using namespace std;
typedef struct no
{
int data;
struct no *lc,*rc;
}node;
node *creat(int n)
{
node *p;
p=new node;
p->data=n;
p->lc=NULL;
p->rc=NULL;
return p;
}
void bulid(node *&root,int n)
{
if(!root)
{
root=creat(n);
}
else
{
if(n>root->data)
bulid(root->rc,n);
else
bulid(root->lc,n);
}
}
bool judge(node *root,node *p)
{
if(!root&&!p) return true;
if(root&&p)
{
if(p->data==root->data)
{
return (judge(root->lc,p->lc)&&judge(root->rc,p->rc));
}
}
return false;
}
int main()
{
int n,l;
while(scanf("%d",&n)&&n)
{
scanf("%d",&l);
node *p;
p=NULL;
int k;
for(int i=0;i<n;i++)
{
scanf("%d",&k);
bulid(p,k);
}
while(l--)
{
node *q;
q=NULL;
for(int i=0;i<n;i++)
{
scanf("%d",&k);
bulid(q,k);
}
if(judge(p,q))
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}
数据结构实验之查找一:二叉排序树
最新推荐文章于 2018-12-09 23:04:48 发布