From 6666c2662969ae417cca3179ae30ba99c651e5ca Mon Sep 17 00:00:00 2001 From: ViolentAyang <76544389+ViolentAyang@users.noreply.github.com> Date: Fri, 18 Mar 2022 15:01:51 +0800 Subject: [PATCH] =?UTF-8?q?Create=20=E5=A4=B4=E6=8F=92=E6=B3=95=E5=BB=BA?= =?UTF-8?q?=E7=AB=8B=E5=8D=95=E9=93=BE=E8=A1=A8.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 链表/头插法建立单链表.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 链表/头插法建立单链表.c diff --git a/链表/头插法建立单链表.c b/链表/头插法建立单链表.c new file mode 100644 index 0000000..9064d60 --- /dev/null +++ b/链表/头插法建立单链表.c @@ -0,0 +1,40 @@ +#include +#include + +typedef struct LNode{ + int data; + struct LNode *next; +}LNode,*LinkList; + +LinkList List_HeadInsert(LinkList L){ + LinkList s; + int x; + L = (LinkList)malloc(sizeof(LNode)); + L->next = NULL; + scanf("%d",&x); + while(x!=9999){ + s = (LinkList)malloc(sizeof(LNode)); + s->data = x; + s->next = L->next; + L->next = s; + scanf("%d",&x); + } + return L; +} + +void List_Print(LinkList L){ + LinkList p = L->next; + printf("链表的元素为:\n"); + while(p){ + printf("%d\t",p->data); + p = p->next; + } +} + +int main() +{ + LinkList L; + L = List_HeadInsert(L); + List_Print(L); + return 0; +}