急问一指针问题!在线等!
这是一个输入数据,建立二叉排序树的程序:
#include<stdio.h>
#include<stdlib.h>
struct node
{
struct node *left, *right;
int data;
int l,r;
};
void view(struct node *);
void insert(struct node *, struct node *);
struct node *Head = NULL;
void main(void)
{
int num;
char cha;
struct node *up, *p;
clrscr();
printf("Please input a serie of numbers end of ;:\n");
do{
scanf("%d", &num);
cha = getchar();
INSERT(Head, num);
}
while(cha != ';');
view(Head);
getchar();
getchar();
}
void INSERT(struct node *h, int num)
{
struct node *p = (struct node *)malloc(sizeof(struct node));
p->left = NULL;
p->right = NULL;
p->l = 0;
p->r = 0;
p->data = num;
insert(h, p);
}
void insert(struct node *h, struct node *p)
{
if(h == NULL)
{
h = p;
}
else
{
if(h->data > p->data)
{
h->l = 1;
insert(h->left, p);
}
else
{
h ->r = 1;
insert(h->right, p);
}
}
}
问题是:INSERT函数和insert函数中,Head作为参数进行调用,却没法建立树,请解答。