#include<bits/stdc++.h>
using namespace std;
struct node
{
char data;
node *lchild,*rchild;
};
node *creat(char first[],char mid[],int len)
{
if(len<=0)
return NULL;
node *t;
t = new node();
t->data = first[0];
int i;
for(i=0;i<len;i++)
{
if(mid[i]==first[0])
break;
}
t->lchild = creat(first+1,mid,i);
t->rchild = creat(first+i+1,mid+i+1,len-i-1);
return t;
}
void finorder(node *root)
{
node *t;
t = new node();
t = root;
if(t==NULL)
return;
finorder(t->lchild);
finorder(t->rchild);
cout<<t->data;
}
int main()
{
char str1[110],str2[110];
cin>>str1>>str2;
node *root2 = new node();
int len = strlen(str2);
root2 = creat(str1,str2,len);
finorder(root2);
return 0;
}
数据结构上机测试4.1:二叉树的遍历与应用1
最新推荐文章于 2024-01-01 14:00:10 发布