创建单链表后按序号查找出现读取访问权限冲突

**创建单链表后按序号查找:
引发了异常: 读取访问权限冲突。
L 是 nullptr。

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

typedef int ElemType;
typedef struct LNode {
ElemType data;
struct LNode* next;
}LNode,*LinkList;

头插法新建链表
LinkList CreateList1(LinkList& L)
{
LNode* 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;

}

尾插法新建链表
LinkList CreateList2(LinkList& L)
{
int x;
L = (LinkList)malloc(sizeof(LNode)); //一开始为空表,先申请头结点,带头结点的链表
LNode* s, * r = L; //LinkList s,r=L ,r链表表尾结点
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;

}

按序号查找
LNode* GetElem(LinkList L, int i)
{

int j = 1;
LNode* p = L->next; //让p指向第一个结点 LNode*等价于LinkList
if (i == 0)   //(LinkList L, int i)查找0则认为是查找头结点
    return L;
if(i<1)
    return NULL;
while (p && j < i)
{
    p = p->next;
    j++;
}
return p;

}

bool ListFrontInsert(LinkList L, int i, ElemType e)
{
LinkList p = GetElem(L, i - 1); //拿到要插入位置的前一个位置的地址值
if (NULL == p)
return false; //i不对
LinkList s = (LinkList)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
return true;
}

LNode* LocateElem(LinkList L, ElemType e)
{
LNode* p = L->next;
while (p != NULL && p->data != e)
p = p->next;
return p;

}

void PrintList(LinkList& L)
{
L = L->next;
while (L != NULL)
{
printf("%3d", L->data);
L = L->next;
}

}

int main()
{
LinkList L; //链表头,是结构体指针类型
LinkList search;
/CreateList1(L);/ //头插法,输入数据可以为3 4 5 6 7 9999
CreateList2(L); //尾插法,输入数据可以为3 4 5 6 7 9999
PrintList(L);
search = GetElem(L, 2);
if (search != NULL)
{
printf("按序号查找成功\n");
printf("%d\n", search->data); //search返回的是一个结构体指针
}

search = LocateElem(L, 6);
if (search != NULL)
{
/printf("按序号查找成功\n");
    printf("%d\n", search->data);   //search返回的是一个结构体指针

ListFrontInsert(L, 2, 99);
PrintList(L);
return 0;

}

img

img


求问大家怎么修改哇