#include <stdio.h>
#include <stdlib.h>
struct node
{
int date;
struct node* next;
};
int main()
{
struct node *p, *p1, *head;
head = p = ( struct node* )malloc(sizeof(struct node)); //分配节点空间
scanf_s("%d", &p->date);
while (p->date != 0)
{
p1 = ( struct node* )malloc(sizeof(struct node)); //分配节点空间
p->next = p1; //指向下一个节点
p = p1;
scanf_s("%d", &p->date);
}
p->next = NULL; //链表尾指向空
//打印链表内容
p = head;
while (p->next != NULL)
{
printf("%d\t", p->date);
p = p->next;
}
printf("%d\t", p->date);
}
单向链表(1)-创建
最新推荐文章于 2023-07-17 23:54:28 发布