二叉排序树
来源:互联网 发布:查看网络运营商 编辑:程序博客网 时间:2024/06/02 02:12
注意: 建立好二叉排序树之后,只需判断两个二叉排序树的前序遍历是否相同即可。
<pre name="code" class="cpp">#include<bits/stdc++.h>using namespace std;typedef struct node{ char data; struct node * lchild; struct node * rchild;}node,*Tree;char a[1001],b[1001],st1[1001],st2[1001];int i,j;Tree creat(Tree &t,char x){ if(t==NULL) { t=new(node); t->data=x; t->lchild=NULL; t->rchild=NULL; } else { if(x<t->data) { t->lchild=creat(t->lchild,x); } else { t->rchild=creat(t->rchild,x); } } return t;}void xian(Tree &t){ if(t!=NULL) { a[i++]=t->data; xian(t->lchild); xian(t->rchild); }}void xiannext(Tree &t){ if(t!=NULL) { b[j++]=t->data; xiannext(t->lchild); xiannext(t->rchild); }}int main(){ int n; Tree t1,t2; while(cin>>n&&(n!=0)) { cin>>st1; t1=NULL; for( i=0;st1[i]!='\0';i++) { t1=creat(t1,st1[i]); } i=0; xian(t1); a[i]='\0'; while(n--) { cin>>st2; t2=NULL; for( j=0;st2[j]!='\0';j++) { t2=creat(t2,st2[j]); } j=0; xiannext(t2); b[j]='\0'; if(strcmp(a,b)) { cout<<"NO"<<endl; } else { cout<<"YES"<<endl; } } }}
0 0
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- Linux的档案权限及目录配置(一)
- Go语言基础:变量,常量,Boolean,字符串,iota枚举
- org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].Standard
- My First Swift APP
- 新闻客户端01 - 初始化项目结构
- 二叉排序树
- Linux的档案权限及目录配置(3)
- CSS Sprites(CSS雪碧图)利用background-position从大图中扣出小图
- Mahout算法集
- 基带通信相关概念
- linux静态库的生成与使用(转)
- 使用Java库中的类
- Linux的档案权限及目录配置(4)
- hdu 4348 可持久化线段树(区间和