标签:排序二叉树
#include<iostream> #include<string.h> using namespace std; char c[100],d[100]; int o=0,e=0; typedef struct bitnode { char data; struct bitnode *lchild,*rchild; }bitnode,*bitree; void insert(bitree &t1,char key) { if(t1==NULL) { t1=new bitnode; t1->lchild=t1->rchild=NULL; t1->data=key; return ; } else { if(key<t1->data) insert(t1->lchild,key); else insert(t1->rchild,key); } } void preorder(bitree t) { if(t!=NULL) { c[o++]=t->data; preorder(t->lchild); preorder(t->rchild); } } void postorder(bitree t3) { if(t3!=NULL) { postorder(t3->lchild); postorder(t3->rchild); d[e++]=t3->data; } } int main() { char a[100],b[100]; int n,len,i; bitree t1; while(cin>>n) { if(n==0) { break; } t1=NULL; cin>>a; len=strlen(a); for(i=0;i<len;i++) { insert(t1,a[i]); } preorder(t1); c[o]='\0'; postorder(t1); d[e]='\0'; for(i=0;i<n;i++) { cin>>b; if(strcmp(a,b)==0) cout<<"YES"<<endl; else if(strcmp(b,c)==0) cout<<"YES"<<endl; else if(strcmp(b,d)==0) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0; }
标签:排序二叉树
原文地址:http://blog.csdn.net/r_misaya/article/details/40662463