include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
typedef struct bitnode{
char data;
struct bitnode lchild,rchild;
}bitnode,bitree;
void createbitree(bitree& bt,int &n,char pre[]){
char c=pre[n];
if(c==’#’){
bt=NULL;
return;
}
n+=1;
bt=(bitnode )malloc(sizeof(bitnode));
bt->data=c;
createbitree(bt->lchild,n,pre);
n+=1;
createbitree(bt->rchild,n,pre);
}
void preorder(bitree bt){
if(bt!=NULL){
cout<[HTML_REMOVED]data;
preorder(bt->lchild);
preorder(bt->rchild);
}
}
void inorder(bitree bt){
if(bt!=NULL){
inorder(bt->lchild);
cout<[HTML_REMOVED]data;
inorder(bt->rchild);
}
}
int main(){
bitree p;
char pre[]={‘a’,’b’,’d’,’#’,’#’,’e’,’#’,’g’,’#’,’#’,’c’,’f’,’#’,’#’,’#’};
int m=0;
int& n = m;
createbitree(p,n,pre);
preorder(p);
cout<<endl;
inorder(p);
free(p);
}