文章
37
粉丝
168
获赞
13
访问
287.1k
#include <bits/stdc++.h>
using namespace std;
typedef struct BinNode{
char e;
struct BinNode* lchild;
struct BinNode* rchild;
}BinNode,*BinTree;
char s[100];
int cnt;
void create(BinTree &bt){
if(cnt>=strlen(s)) return;
char c=s[cnt++];
if(c=='#') bt=NULL;
else{
bt=(BinTree)malloc(sizeof(BinNode));
bt->e=c;
bt->lchild=NULL;
bt->lchild=NULL;
create(bt->lchild);
create(bt->rchild);
}
}
void midOrdTrave(BinTree &T){
if(T!=NULL){
midOrdTrave(T->lchild);
cout<<T->e<<" ";
midOrdTrave(T->rchild);
}
}
void mid_t(BinTree bt){
if(bt!=NULL){
mid_t(bt->lchild);
cout<<bt->e;
mid_t(bt->rchild);
}
}
int main()
{
while(cin>>s){
cnt=0;
BinTree bt;
create(bt);
midOrdTrave(bt);
cout<<endl;
}
}
登录后发布评论
暂无评论,来抢沙发