#include"stdio.h"
#include "stdlib.h"
#define NULL 0
#define LEN sizeof(struct node)
typedef int datatype;
typedef struct node
{ datatype data;
struct node *next;
}linklist;
linklist *hrear_creat()
{
int x;
linklist *head,*p,*rear;
head=(struct node*)malloc (LEN);
head->data=-999;
rear=head;
printf("请输入以整数0结束符");
scanf("%d,&x");
while(x!=0)
{
p=(struct node*)malloc(LEN);
p->data=x;
rear->next=p;
rear=p;
scanf("%d",&x);
}
rear->next=NULL;
return(head);
}
int main()
{
linklist *hrear_creat();
return 0;
}
用尾插法建立一个带头结点的单链表的算法
最新推荐文章于 2022-06-11 22:47:34 发布
本文介绍了一个使用C语言实现的简单链表创建程序。该程序通过定义结构体类型来构造链表节点,并通过一系列输入操作动态创建链表。文章包含完整的源代码,展示了如何初始化链表头结点、分配内存、接收用户输入并连接链表。
4684





