初学链表,我想请问坛里一些问题。
首先,输出结果链表建立没有问题,但是首结点貌似未赋值在我的代码它更像是头结点。
我想请教一下 如何操作才能让首节点成为实际有信息的第一个节点 而非头结点
int main()
{
Node *head ;
init_list(&head);
TCcreate_list(&head);
print_list(head);
printf("\n%d",head->value);
return 0;
}
void init_list(Node **L)
{
(*L) = (Node *) malloc (sizeof(Node));
(*L)->next = NULL;
(*L) ->value = 0;
}
void TCcreate_list(Node **phead)
{
Node *p;
Node *last;
int num;
scanf("%d",&num);
while(num!=-1)
{
p = (Node *)malloc(sizeof(Node));
p->value =num;
p->next =NULL;
last = *phead;
while(last->next)
{
last =last->next;
}
last ->next = p;
scanf("%d",&num);
}
}
printf("结束循环");
}