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(pNULL) return;
show(p->lc);
cout<
show(p->rc);
}
int main(){
cin>>s;
Node p=NULL;
int k=0;
p=build(p,k);
show(p);
return 0;
}