二叉树输出不了啊
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
struct Tree
{
int a;
struct Tree *lchild;
struct Tree *rchild;
}*p,*head;
int GetFree(struct pTree *);
int PlayFree(struct Tree *p);
void main ()
{
head=(struct Tree*)malloc(sizeof(struct Tree));
head=p;
GetFree(p);
p=head;
PlayFree(p);
}
int GetFree(struct Tree *p)
{
char a,b;
printf("输入根节点:此根节点为空请输入‘#‘符!");
scanf("%c",&a);getchar();
if(a=='#')
{
p=NULL;
}
else
{
p=(struct Tree*)malloc(sizeof(struct Tree));
p->a=a;
printf("此根节点是否要有左子树?有的话请输入'+',没有请输入'-',输入其他字符则结束程序!");
scanf("%c",&b);getchar();
if(b=='+')
{
GetFree(p->lchild);//构建左树
}
else if(b=='-')
{
p->lchild=NULL;
}
else
{
return 0;
}
printf("此根节点是否要有右子树?有的话请输入'+',没有请输入'-',输入其他字符则结束程序!");
scanf("%c",&b);getchar();
if(b=='+')
{
GetFree(p->rchild);//构建左树
}
else if(b=='-')
{
p->rchild=NULL;
}
else
{
return 0;
}
}
return 1;
}
int PlayFree(struct Tree *p)//先序遍历
{
printf("sadasdasdasd");
if(p!=NULL)
{
printf("%c",p->a);
PlayFree(p->lchild);
PlayFree(p->rchild);
}
return 0;
}
我百度了一下,说要把在函数的参数那加上地址符,但是我加上去之后,却出现一大堆错误,不知道如何去改。
我还有一个疑问,就是指针不就是一个地址吗?为什么还要加地址符?

