- #include<stdio.h>
- #include<stdlib.h>
- struct node{
- struct node* left;
- char c;
- struct node* right;
- };
- char preo[55],ino[55];
- int num[55];
- int p;
- int len;
- void en(){
- int i,j;
- for(i=0;i<len;i++)
- for(j=0;j<len;j++)
- if(preo[i]==ino[j]){
- num[i]=j;
- break;
- }
- /*num[i] = 10000;*/
- return;
- }
- void erect(struct node* m,int w,int l){
- struct node* t;
- if(num[p+1]<w){
- p++;
- t=m->left;
- t->c=preo[p];
- t->left=t->right=NULL;
- erect(t,num[p],w);
- }
- if(num[p+1]<l){
- p++;
- t=m->right;
- t->c=preo[p];
- t->left=t->right=NULL;
- erect(t,num[p],l);
- }
- return;
- }
- void visit(struct node* m){
- if(m){
- if(m->left)visit(m->left);
- if(m->right)visit(m->right);
- }
- return;
- }
- struct node* root;
- int main(){
- int n;
- while(n--){
- en();
- root->c=preo[0];
- root->right=root->left=NULL;
- p=0;
- erect(root,num[0],len);
- visit(root);
- }
- return 0;
- }
Raw Paste