#include<stdio.h>
#include<stdlib.h>
struct list
{
int data;
struct list *next;
};
int main()
{
struct list *head, *p;
int n = 0;
int num = 0;
head = NULL;
p = (struct list*)malloc(sizeof(struct list));
head = p;
printf("请输入n个数:");
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &num);
p->data = num;
p->next = (struct list*)malloc(sizeof(struct list));
if (i == n - 1)
{
p->next = NULL;
}
else
{
p = p->next;
}
}
p = head;
while (p != NULL)
{
printf("%d ", p->data);
p = p->next;
}
system("pause");
return 0;
}
【C语言】创建一个链表
最新推荐文章于 2025-02-22 17:13:26 发布
9574

被折叠的 条评论
为什么被折叠?



