建了一个链表,用 for 输出 为什么只能输出一个节点内的值
# include <stdio.h># include <malloc.h>
struct Node
{
int date;
struct Node * Next;
};
struct Node * create_list(void);
void outlist(struct Node *);
int main(void)
{
struct Node * pHead = NULL;
pHead = create_list();
outlist(pHead);
return 0;
}
struct Node * create_list(void)
{
struct Node * nHead = (struct Node *)malloc(sizeof(struct Node));
struct Node * nTail;
nTail = nHead;
nTail->Next = NULL;
int i, len, val;
printf("请输入需要建立的节点数:");
scanf("%d", &len);
for (i=0; i<len; i++)
{
printf("第%d个节点的值为:", i+1);
scanf("%d", &val);
struct Node * New = (struct Node *)malloc(sizeof(struct Node));
New->date = val;
nTail->Next = New;
New->Next = NULL;
nTail = New;
}
return nHead;
}
void outlist(struct Node * pHead)
{
struct Node * p = pHead->Next;
int i;
for (i=0; i<3; i++);
{
printf("%d ", p->date);
p = p->Next;
}
}