填空题
以下程序的功能是建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1时,表示输入结束(链表头结点的data域不放数据,表空的条件是ph->next==NULL),请填空。
#include <stdio.h>
struct list { int data;struct list *next;};
struct list *creatlist( )
{ struct list *p,*q,*ph;int a;ph=(struct list*)malloc(sizeof(struct list));
p=q=ph;printf("Input an integer number;entre-1 to end:\n");
scanf("%d",&a);
while(a!=-1)
{ p=(struct list*)malloc(sizeof(struct list));
[14] =a;q->next=p; [15] =p;scanf("%d",&a);}
p->next=’\0’;return(ph);}
main( )
{stuct list * head;head=creatlist();}
【参考答案】
p->data