大会员可查看代码,点此开通大会员
#include<cstdio>
#include<stdlib.h>
#include<string.h>
char temp[120];
bool flag = false;
int nlen;
int next;
typedef struct node
{
char nValue;
node *pLeft;
node *pRight;
}BinaryTree;
void CreateBinaryTree(BinaryTree**pTree)
{
if(next>=nlen)return;
char c = temp[next++];
if(c=='#')return;
*pTree =(BinaryTree*)malloc(sizeof(BinaryTree));
(*pTree)->nValue = c;
(*pTree)->pLeft = NULL;
(*pTree)->pRight = NULL;
CreateBinaryTree(&((*pTree)->pLeft));
CreateBinaryTree(&((*pTree)->pRight));
}
void Per(BinaryTree*p)
{
if(p==NULL)return;
printf("%c ",p->nValue);
Per(p->pLeft);
Per(p->pRight);
}
void Mid(BinaryTree*p)
{
if(p==NULL)return;
Mid(p->pLeft);
printf("%c ",p->nValue);
Mid(p->pRight);
}
int main()
{
while(~scanf("%s",temp))
{
next = 0;
nlen = strlen(temp);
BinaryTree *pRoot =NULL;
CreateBinaryTree(&pRoot);
Mid(pRoot);
puts("");
}
return 0;
}