文章
35
粉丝
134
获赞
55
访问
24.6k
#include <bits/stdc++.h>
using namespace std;
typedef struct node{
char data;
struct node *lchild,*rchild;
}*BiTree;
void PreCreate(BiTree &T){
char c;
cin>>c;
if(c=='0') T=NULL;
else {
T=new node;
T->data=c;
PreCreate(T->lchild);
PreCreate(T->rchild);
}
}
void preOrder(BiTree T){
if(T==NULL) return;
cout<<T->data<<" ";
preOrder(T->lchild);
preOrder(T->rchild);
}
void inOrder(BiTree T){
if(T==NULL) return;
inOrder(T->lchild);
cout<<T->data<<" ";
inOrder(T->rchild);
}
void postOrder(BiTree T){
if(T==NULL) return;
postOrder(T->lchild);
postOrder(T->rchild);
cout<<T->data<<" ";
}
int leaf(BiTree T){
if(T==NULL) return 0;
if(T->lchild==NULL&&T->rchild==NULL) return 1;
return leaf(T->lchild)+leaf(T->rchild);
}
int main(){
BiTree T;
PreCreate(T);
preOrder(T);cout<<endl;
inOrder(T);cout<&...
登录后发布评论
暂无评论,来抢沙发