↖(^ω^)↗

###### ACM 数据结构-二叉树 HDU 3791二叉搜索树
<div class="panel_title" align="left">Problem Description</div><div class="panel_content">判断两序列是否为同一二叉搜索树序列</div><div class="panel_bottom"> </div>
<div class="panel_title" align="left">Input</div><div class="panel_content">开始一个数n，(1<=n<=20) 表示有n个需要判断，n= 0 的时候输入结束。

<div class="panel_title" align="left">Output</div><div class="panel_content">如果序列相同则输出YES，否则输出NO
</div><div class="panel_bottom"> </div>
<div class="panel_title" align="left">Sample Input</div><div class="panel_content"><pre><div style="FONT-FAMILY: Courier New,Courier,monospace">2
567432
543267
576342
0</div>

Sample Output
YES NO

Source

#include <iostream>
#include <cstring>
#include <cstdio>
#include <stdlib.h>
using namespace std;

int a[30],b[30],cnt = 0;

typedef struct tree
{
tree *l,*r;
int num;
} tree;
tree *root;
tree *creat(int x)
{
tree *t = (tree*)malloc(sizeof(tree));
t->l = 0;
t->r = 0;
t->num = x;
return t;
}

tree *inster(tree *s,int x)
{
tree *t;
if(s == NULL)
{
t = creat(x);
s = t;
}
else
{
if(x <= s->num)
s->l = inster(s->l,x);
else
s->r = inster(s->r,x);
}
return s;
}

void libian(tree *root)
{
if(root!=NULL)
{
b[cnt++] = root->num;
libian(root->l);
libian(root->r);
}
}

int main()
{
int n;
while(cin >> n,n)
{
cnt = 0;
root = NULL;
int tem;
char str[30];
cin >> str;
int len = strlen(str),i;
for(i = 0; i<len; i++)
{
tem = str[i] - '0';
root = inster(root,tem);
}
libian(root);
for(i = 0; i<len; i++)
a[i] = b[i];
while(n--)
{
cnt = 0;
cin >> str;
root = NULL;
for(i = 0; i<len; i++)
{
tem = str[i] - '0';
root = inster(root,tem);
}
libian(root);
for(i = 0; i<len; i++)
if(a[i]!=b[i])
{
cout << "NO" << endl;
break;
}
if(i>=len)
cout << "YES" << endl;
}
}
return 0;
}


#### [ACM] hdu 3791 二叉搜索树

2014-02-24 16:11:14

#### HDOJ 3791 二叉搜索树（二叉树）

2016-07-31 23:33:58

#### 【二叉搜索数】HDU3791二叉搜索树

2016-05-17 19:38:42

#### poj 1577 Falling Leaves（二叉搜索树的简单操作（建立、插入））

2014-08-01 18:57:52

#### HDU - 3791：二叉搜索树

2017-08-17 21:33:55

#### hdu3791（二叉搜索树构造）

2016-07-29 17:11:33

#### 数据结构-二叉树和二叉查找树

2015-12-20 17:44:30

#### HDU 3791 二叉搜索树

2014-03-14 15:50:14

#### 数据结构与算法之二叉搜索树插入、查询与删除

2016-10-28 15:11:45

#### hdu 3791 二叉搜索树（二叉树)

2014-03-17 19:01:25

## 不良信息举报

ACM 数据结构-二叉树 HDU 3791二叉搜索树