#include <iostream>
#include <vector>
using namespace std;
#define END -1
#define Max_Size 11
//二叉查找树的顺序存储结构
//判断几个不同的序列构成的二叉查找树是否相同
//所以输入的排序都是前n个数字的排序
typedef struct Node{
int left;
int right;
}Node;
//注意,如果是数组做参数,形参的写法是(int *a)实参直接写数组名,这样数组的值会真正改变
//但向量做参数时,要把向量看成原子类型,即要引用传递才能真正改变向量中元素的值 ,实参直接写向量名
void Initial_Tree(vector<Node>& Tree,int N)
{
for(int i=1;i<=N;i++)
{
Tree[i].left=END;
Tree[i].right=END;
}
}
void Build_Tree(vector<Node>& Tree,int N)
{
cout<<"Please input the figures in array(from 1 to max)";
int value,root,pre;
cin>>value;
root=value;
pre=root;
for(int i=1;i<=N-1;i++)
{
cin>>value;
while(1)
{
if(value>pre&&Tree[pre].right==END)
{
Tree[pre].right=value;
pre=root;
break;
}
if(value>pre&&Tree[pre].right!=END)
{
pre=Tree[pre].right;
}
if(value<pre&&Tree[pre].left==END)
{
Tree[pre].left=value;
pre=root;
break;
}
if(value<pre&&Tree[pre].left!=END)
{
pre=Tree[pre].left;
}
}
}
}
bool Compare_Tree(vector<Node> Tree1,vector<Node> Tree2,int N)
{
for(int i=1;i<=N;i++)
{
if(!(Tree1[i].left==Tree2[i].left&&Tree1[i].right==Tree2[i].right))
{
return false;
}
}
return true;
}
int main()
{
int N,L;
while(1)
{
cout<<"Please input the length of array:(less than 10)";
cin>>N;
if(N==0)
{
return 0;
}
else
{
cout<<"Please input the count of array to compare:";
cin>>L;
vector<Node> Tree(Max_Size);
vector<Node> vec(Max_Size);
Initial_Tree(Tree,N);
Build_Tree(Tree,N);
for(int i=0;i<L;i++)
{
cout<<"Please input the array"<<i+1<<"to compare"<<endl;
Initial_Tree(vec,N);
Build_Tree(vec,N);
if(Compare_Tree(Tree,vec,N))
{
cout<<"\n"<<"yes";
}
else
{
cout<<"\n"<<"no";
}
}
}
}
}