先序建立二叉树和先序遍历二叉树问题,为什么输入d##后输出为100,求指教???
#include<stdio.h>#include<malloc.h>
#include<stdlib.h>
#define FAILURE 0
#define ERROR -2
#define OK 1
typedef char elemtype;
typedef struct NODE
{
elemtype data;
struct NODE *lchild,*rchild;
}NODE,*TREE;
TREE precreateTree(TREE *t)
{
elemtype ch;
ch=getchar();
if(ch=='#') *t=NULL;
else
{
if(!(*t=(TREE)malloc(sizeof(NODE)))) exit(FAILURE);
(*t)->data=ch;
precreateTree(&((*t)->lchild));
precreateTree(&((*t)->rchild));
}
return *t;
}
int pretraverseTree(TREE t)
{
if(t)
{
printf("%d",t->data);
pretraverseTree(t->lchild);
pretraverseTree(t->rchild);
}
return OK;
}
void main()
{
TREE p;
p=(TREE)malloc(sizeof(NODE));
p=precreateTree(&p);
pretraverseTree(p);
printf("\n");
}