满分代码,有疑问欢迎留言
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
long long int N,L,x;//声明变量
typedef struct TreeNode *List;//构建树结构
typedef List Position;
struct TreeNode{
int Data;
List Left;
List Right;
};
List B=NULL,B1=NULL;//建立两颗用来比较的树
List Insert(int X,List BST){
if(!BST){
BST=(List)malloc(sizeof(struct TreeNode));
BST->Data=X;
BST->Left=BST->Right=NULL;
}else{
if(X<BST->Data)
BST->Left=Insert(X,BST->Left);
else if(X>BST->Data)
BST->Right=Insert(X,BST->Right);
}
return BST;
}
//建立比较树
List ReadPoly(){
for(int i=0;i<N;i++){
cin>>x;
B1=Insert(x,B1);
}
return B1;
}
int compare1(List T1,List T2){
if(T1==NULL&&T2==NULL)
return 1;
if(T1&&T2)
if(T1->Data==T2->Data)
if(compare1(T1->Left,T2->Left)&&compare1(T1->Right,T2->Right))
return 1;
return 0;
}
int main(){
while(cin>>N&&N!=0){
B=NULL;
cin>>L;
for(int i=0;i<N;i++){
cin>>x;
B=Insert(x,B);
}
while(L--){
B1=NULL;
B1=ReadPoly();
if(compare1(B,B1))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
return 0;
}