数据结构实验之查找一:二叉排序树

来源:互联网 发布:linux session 编辑:程序博客网 时间:2024/06/06 08:29



#include<bits/stdc++.h>using namespace std;typedef struct node{    char data;    struct node *lchild;    struct node * rchild;}node, *Tree;char a[200],b[200];int st1[200],st2[200];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,l;    Tree t1,t2;    while(cin>>n&&n)    {        cin>>l;        t1=NULL;        for(i=0;i<n;i++)        {            cin>>st1[i];            t1=creat(t1,st1[i]+'\0');        }        i=0;        xian(t1);        a[i]='\0';        while(l--)        {            t2=NULL;            for(j=0;j<n;j++)            {                cin>>st2[j];                t2=creat(t2,st2[j]+'\0');            }            j=0;            xiannext(t2);            b[j]='\0';            if(strcmp(a,b))            {                cout<<"No"<<endl;            }            else            {                cout<<"Yes"<<endl;            }        }    }}


0 0