AcWing 3384. 二叉树遍历
原题链接
简单
作者:
老林的提词器
,
2021-06-05 21:57:01
,
所有人可见
,
阅读 477
#include<iostream>
using namespace std;
typedef struct node{
char data;
struct node *lchild,*rchild;
}Node,*bitree;
//创建二叉树
bitree create(){
bitree T;
char ch;
cin>>ch;
if(ch!='#'){
T = new Node;
T->data = ch;
T->lchild = create();
T->rchild = create();
}
else{
T = NULL;
}
return T;
}
//中序遍历
void midOrder(bitree T){
if(T->lchild) midOrder(T->lchild);
cout<<T->data<<' ';
if(T->rchild) midOrder(T->rchild);
}
int main(){
bitree T;
T = create();
midOrder(T);
}