pintia7-1 二叉树遍历应用

include

include

using namespace std;
typedef struct node{
char ch;
node* lc,rc;
}node,
Node;
string s;
Node build(Node p,int& k){
if(s[k]'#'){
k++;
return NULL;
}
p=new node();
p->ch=s[k++];
p->lc=build(p->lc,k);
p->rc=build(p->rc,k);
return p;
}
void show(Node p){
if(p
NULL) return;
show(p->lc);
cout<ch<<' ';
show(p->rc);
}
int main(){
cin>>s;
Node p=NULL;
int k=0;
p=build(p,k);
show(p);
return 0;
}

posted @ 2021-10-17 19:21  Lindseyyip  阅读(46)  评论(0编辑  收藏  举报