From 890efb962c0597ec8df3da29367eef9cb7a2aa01 Mon Sep 17 00:00:00 2001 From: ViolentAyang <76544389+ViolentAyang@users.noreply.github.com> Date: Fri, 18 Mar 2022 14:09:02 +0800 Subject: [PATCH] =?UTF-8?q?Create=20=E5=B0=BE=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..90871ad --- /dev/null +++ b/链表/尾插法建立单链表.c @@ -0,0 +1,40 @@ +#include +#include + +typedef struct LNode{ + int data; + struct LNode *next; +}LNode,*LinkList; + +LinkList List_TailInsert(LinkList L){ + int x; + L = (LinkList)malloc(sizeof(LNode)); + LinkList s,r = L; + scanf("%d",&x); + while(x!=9999){ + s = (LinkList)malloc(sizeof(LNode)); + s->data = x; + r->next = s; + r = s; + scanf("%d",&x); + } + r ->next = NULL; + 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_TailInsert(L); + List_Print(L); + return 0; +}