//// Created by 黎圣 on 2023/8/25.//#include"iostream"typedefstructTreeNode{char data;structTreeNode*lchild,*rchild;}*tree;voidCreateTree(tree &t){char ch =getchar();if(ch =='#')
t =NULL;else{
t =(structTreeNode*)malloc(sizeof(structTreeNode));
t->data = ch;
t->lchild =NULL;
t->rchild =NULL;CreateTree(t->lchild);CreateTree(t->rchild);}}structTreeNode*pre =NULL,*head =(structTreeNode*)malloc(sizeof(structTreeNode));
tree Inorder(tree &t){if(t){Inorder(t->lchild);if(t->lchild ==NULL&& t->rchild ==NULL){//是否是第一个//是if(pre ==NULL){
head = t;
pre = t;}//不是第一个else{
pre->rchild = t;
pre = t;}}Inorder(t->rchild);}return head;}intmain(){
tree t;CreateTree(t);//ABD##E##CF##G##Inorder(t);while(head){printf("%c ", head->data);
head = head->rchild;}return0;}