#include <bits/stdc++.h>
#define ElemType char
using namespace std;
ElemType arr[1123];
ElemType res[1123];
typedef struct BinaryTree
{
ElemType data;
struct BinaryTree *Left;
struct BinaryTree *Right;
}Node;
void BstCreat(Node *&root, ElemType x);
bool CmpBst(Node *root, Node *p);
int main()
{
int l,n;
while(cin >> n >> l && n)
{
Node *root = new Node;
root = NULL;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
}
for(int i = 0; i < n; i++)
{
BstCreat(root, arr[i]);
}
while(l--)
{
Node *p = new Node;
p = NULL;
for(int i = 0; i < n; i++)
{
cin >> res[i];
}
for(int i = 0; i < n; i++)
{
BstCreat(p, res[i]);
}
int f = CmpBst(root, p);
if(!f)
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
}
}
}
return 0;
}
void BstCreat(Node *&root, ElemType x)
{
if(!root)
{
root = new Node;
root->data = x;
root->Left = NULL;
root->Right = NULL;
}
else
{
if(x < root->data)
{
BstCreat(root->Left, x);
}
else
{
BstCreat(root->Right, x);
}
}
}
bool CmpBst(Node *root, Node *p)
{
if(root == NULL && p == NULL)
{
return true;
}
else if(root == NULL || p == NULL)
{
return false;
}
else
{
if(CmpBst(root->Left, p->Left) && CmpBst(root->Right, p->Right))
{
return true;
}
}
return false;
}
二叉排序树
最新推荐文章于 2024-12-08 08:30:00 发布
