学术网站怎么做,域名网站建设教程,wordpress 小程序主题,注册企业邮箱需要什么二叉排序树 Time Limit: 1000MS Memory Limit: 65536KBSubmit Statistic DiscussProblem Description 二叉排序树的定义是#xff1a;或者是一棵空树#xff0c;或者是具有下列性质的二叉树#xff1a; 若它的左子树不空#xff0c;则左子树上所有结点的值均小于它的根结点… 二叉排序树 Time Limit: 1000MS Memory Limit: 65536KBSubmit Statistic DiscussProblem Description 二叉排序树的定义是或者是一棵空树或者是具有下列性质的二叉树 若它的左子树不空则左子树上所有结点的值均小于它的根结点的值 若它的右子树不空则右子树上所有结点的值均大于它的根结点的值 它的左、右子树也分别为二叉排序树。 今天我们要判断两序列是否为同一二叉排序树 Input 开始一个数n(1n20) 表示有n个需要判断n 0 的时候输入结束。 接下去一行是一个序列序列长度小于10包含(0~9)的数字没有重复数字根据这个序列可以构造出一颗二叉排序树。 接下去的n行有n个序列每个序列格式跟第一个序列一样请判断这两个序列是否能组成同一颗二叉排序树。(数据保证不会有空树) Output Example Input 2
123456789
987654321
432156789
0 Example Output NO
NO #includeiostream
#includestring.h
using namespace std;
char c[100],d[100];
typedef struct node
{char data;struct node *lchild,*rchild;
}node,*itree;
int o0,e0;
void insert(itree t1,char key)
{if(t1NULL){t1new node;t1-lchildt1-rchildNULL;t1-datakey;return ;}else{if(keyt1-data)insert(t1-lchild,key);else insert(t1-rchild,key);}
}
void pre_order(itree t)
{if(t!NULL){c[o]t-data;pre_order(t-lchild);pre_order(t-rchild);}
}
void post_order(itree t3)
{if(t3!NULL){post_order(t3-lchild);post_order(t3-rchild);d[e]t3-data;}
}
int main()
{char a[100],b[100];int n,len,i;itree t1;while(cinn){if(n0){break;}t1NULL;cina;lenstrlen(a);for(i0;ilen;i){insert(t1,a[i]);}pre_order(t1);c[o]\0;post_order(t1);d[e]\0;for(i0;in;i){cinb;if(strcmp(a,b)0)coutYESendl;else if(strcmp(b,c)0)coutYESendl;else if(strcmp(b,d)0)coutYESendl;elsecoutNOendl;}}return 0;
}