mirror of
https://github.com/ViolentAyang/DataStructureC.git
synced 2026-02-03 02:13:14 +08:00
Create 尾插法建立单链表.c
This commit is contained in:
40
链表/尾插法建立单链表.c
Normal file
40
链表/尾插法建立单链表.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user