#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct Node
{
char c;
Node *left,*right;
};
char s[105];
void build(Node *&root,int &index,int n)
{
if(index==n)
return;
if(s[index]=='#')
{
root=NULL;
index++;
}
else
{
root=new Node;
root->c=s[index];
index++;
build(root->left,index,n);
build(root->right,index,n);
}
}
void print(Node *root)
{
if(root!=NULL)
{
print(root->left);
printf("%c ",root->c);
print(root->right);
}
}
int main()
{
while(cin>>s)
{
Node *root=NULL;
int len=strlen(s);
int index=0;
build(root,index,len);
print(root);
cout<<endl;
}
return 0;
}
二叉树遍历已知先序求中序
最新推荐文章于 2024-05-12 20:01:39 发布