我已经编写了一个代码来附加节点是否为空。我认为我的代码和逻辑是正确的,但我仍然无法得到任何答案。它的编译但运行后没有显示任何结果。请告诉我为什么
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *nxt;
};
void append(struct node *,int);
void display(struct node*);
void append( struct node *q, int num )
{
struct node *temp,*r;
if(q == NULL)
{
temp = (struct node*)malloc(sizeof(struct node));
temp -> data = num;
temp -> nxt = NULL;
q = temp;
}
else
{
temp = q;
while(temp->nxt != NULL)
{
temp = temp->nxt;
}
r = (struct node*)malloc(sizeof(struct node));
r -> data = num;
r -> nxt = NULL;
temp->nxt = r;
}
}
void display(struct node *q)
{
while(q != NULL)
{
printf("%d",q->data);
q = q->nxt;
}
}
int main()
{
struct node *a;
a= NULL;
append(a,10);
append(a,11);
append(a,12);
display(a);
return 0;
}