#include<bits/stdc++.h>
#define endl "\n";
using namespace std;
typedef long long ll;
typedef struct node{
char date;
node *lchild,*rchild;
}BTNode;
void applyBTNode(BTNode *&p){
p=(BTNode*)malloc(sizeof(BTNode));
}
void PreOrderC(BTNode *&t){
char c;
cin>>c;
if(c!='#'){
applyBTNode(t);
t->lchild=NULL;
t->rchild=NULL;
t->date=c;
PreOrderC(t->lchild);
PreOrderC(t->rchild);
}
}
void PreOrder(BTNode *t){
if(t!=NULL){
cout<<t->date;
PreOrder(t->lchild);
PreOrder(t->rchild);
}
}
void InOrder(BTNode *t){
if(t!=NULL){
InOrder(t->lchild);
cout<<t->date;
InOrder(t->rchild);
}
}
void PostOrder(BTNode *t){
if(t!=NULL){
PostOrder(t->lchild);
PostOrder(t->rchild);
cout<<t->date;
}
}
void IOS(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
}
int main(){
IOS();
BTNode *t;
PreOrderC(t);
InOrder(t);
return 0;
}
SWUST OJ 978 输出利用先序遍历创建的二叉树的中序遍历序列
最新推荐文章于 2025-05-19 08:35:23 发布