尾插法建立单链表
#define NULL 0
#include<stdio.h>
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkList;
LinkList List_TailInsert(LinkList &L){
int x;
L = (LinkList)malloc(sizeof(LNode));
LNode *r = L;
scanf("&d",&x);
while (x!=9999)
{
LNode *s = (LNode*)malloc(sizeof(LNode));
s->data = x;
r->next = s;
r = s;
scanf("%d",&x);
}
r->next = NULL;
return L;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/c6aa09bbac7b4f589a09c77496a5df99.png#pic_center)
头插法建立单链表
LinkList List_HeadInsert(LinkList &L){
int x;
L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
scanf("&d",&x);
while (x!=9999)
{
LNode *s = (LNode*)malloc(sizeof(LNode));
s->data = x;
s->next = L->next;
L->next = s;
scanf("%d",&x);
}
return L;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/d1cba7a604bb4d9d9de578f27bca5c31.png#pic_center)