parent
e724ec4d32
commit
2ef5afb45f
@ -1,2 +1,58 @@
|
||||
# dadsadsad
|
||||
|
||||
#include<stdio.h>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
typedef struct bi{
|
||||
char data;
|
||||
struct bi *lchild,*rchild;
|
||||
}tree,*btree;
|
||||
|
||||
void csh(bi* &d){
|
||||
char ch;
|
||||
cin >> ch;
|
||||
if(ch == '#') d=NULL;
|
||||
else
|
||||
{
|
||||
d = new bi;
|
||||
d->data=ch;
|
||||
csh(d->lchild);
|
||||
csh(d->rchild);
|
||||
}
|
||||
}
|
||||
|
||||
void xx(bi* &t){
|
||||
if(t){
|
||||
cout << t->data;
|
||||
xx(t->lchild);
|
||||
xx(t->rchild);
|
||||
}
|
||||
}
|
||||
|
||||
void zx(bi* &t){
|
||||
if(t){
|
||||
zx(t->lchild);
|
||||
cout << t->data;
|
||||
zx(t->rchild);
|
||||
}
|
||||
}
|
||||
|
||||
void hx(bi* &t){
|
||||
if(t){
|
||||
hx(t->lchild);
|
||||
hx(t->rchild);
|
||||
cout << t->data;
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
btree d;
|
||||
cout << "通过先序遍历创建二叉树,#表示空节点" << endl;
|
||||
csh(d);
|
||||
xx(d);
|
||||
cout << "" <<endl;
|
||||
zx(d);
|
||||
cout << "" <<endl;
|
||||
hx(d);
|
||||
cout << "" <<endl;
|
||||
}
|
Loading…
Reference in new issue