#include <stdio.h>
#include <stdlib.h>
struct Node{ //c语言实现结构体的创建
int data;
struct Node *next;
};
int main()
{
struct Node *p1,*head;
for(int i=0;i<10;i++)
{
p1->next=(struct Node *)malloc(sizeof(struct Node));
p1->data=i*4;
if(i==10) p1->next=NULL;
else p2->next=p1;
}
head=p1;
while(head!=NULL)
{
printf("%3d",head->data);
head=head->next;
}
return 0;
}
C语言实现结构体链表的建立
最新推荐文章于 2024-07-08 20:36:47 发布
这篇博客展示了如何使用C语言创建一个动态链表,通过`malloc`动态分配节点并初始化,重点在于链表的插入和遍历操作。作者通过代码实例详细讲解了从头节点创建到显示所有元素的过程。
4379

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



