#includestdio.h#includemalloc.h#includestring.htypedefcharDataType;typedefstructNode{DataTypedata;structNode*leftChild;structNode*rightChild;}*BiTreeNode;voidPrintTree(BiTreeNoderoot,intn)//Ê÷µÄ°¼ÐÎÊä³ö{inti;if(root==NULL)return;PrintTree(root-rightChild,n+1);for(i=0;in-1;i++)printf();if(n0){printf(---);printf(%c\n,root-data);}if(n==0){printf(-);printf(%c\n,root-data);}PrintTree(root-leftChild,n+1);}voidInitiate(BiTreeNode*root)//Ê÷µÄ³õʼ»¯{*root=(BiTreeNode)malloc(sizeof(structNode));(*root)-leftChild=NULL;(*root)-rightChild=NULL;}voidPreOrder(BiTreeNodebt)//Ç°Ðò±éÀúÒÔbtΪ¸ù½áµãÖ¸ÕëµÄ¶þ²æÊ÷{if(bt==NULL)return;printf(%c,bt-data);PreOrder(bt-leftChild);PreOrder(bt-rightChild);}voidInOrder(BiTreeNodebt)//ÖÐÐò±éÀúÒÔbtΪ¸ù½áµãÖ¸ÕëµÄ¶þ²æÊ÷{if(bt==NULL)return;InOrder(bt-leftChild);printf(%c,bt-data);InOrder(bt-rightChild);}intCreattree(DataType*pre,DataType*in,intal,BiTreeNode&T){//Ê÷µÄ´´½¨intk;DataType*i;if(al=0){T=NULL;return0;}for(i=in;iin+al;i++)//²éÕÒ¸ù½áµãif(*pre==*i){k=i-in;//kΪ¸ù½áµãÔÚÖÐÐòÐòÁÐÖÐÏà¶ÔÍ·½áµãµÄ¾àÀëT=(BiTreeNode)malloc(sizeof(structNode));T-data=*i;break;};Creattree(pre+1,in,k,T-leftChild);//½¨Á¢×ó×ÓÊ÷Creattree(pre+k+1,in+k+1,al-k-1,T-rightChild);//½¨Á¢ÓÒ×ÓÊ÷}intmain(){DataTypea[50],b[50];intal,bl;intk=0;BiTreeNoderoot;printf(ÇëÊäÈëÇ°Ðò±éÀú£º);scanf(%s,&a);printf(ÇëÊäÈëÖÐÐò±éÀú£º);scanf(%s,&b);al=strlen(a);bl=strlen(b);Initiate(&root);if(al==bl)Creattree(a,b,al,root);elsek=1;if(k){printf(ÐòÁв»Æ¥Åä);printf(\n);}else{PrintTree(root,0);PreOrder(root);printf(\n);InOrder(root);printf(\n);}}