C初学者一个关于链表的问题
#include<stdio.h>
#include "malloc.h"
#define MaxSize 100
#define error 0;
#define right 1;
typedef int ElemType;
typedef struct Node
{
ElemType data;
struct Node* next;
};
typedef struct Node* LinkList;
void CreateList(LinkList* L, int n, ElemType a[]);
void InsertList(LinkList* L, int i, int n, ElemType e);
void InputList(LinkList* L, int n);
void CreateList(LinkList* L, int n, ElemType a[])
{
LinkList p, r;
*L = (LinkList)malloc(sizeof(Node));
r = *L;
for (int i = 0; i < n; i++)
{
p = (Node*)malloc(sizeof(Node));
p->data = a[i];
r->next = p;
r = p;
}
r->next = NULL;
}
void InsertList(LinkList* L, int i, int n, ElemType e)
{
LinkList p, s;
p = (*L)->next;
int k, j;
for (int k = 0; k < n; k++)
{
if (k == i - 2)
{
s = (LinkList)malloc(sizeof(Node));
s->next = p->next;
p->next = s;
s->data = e;
break;
}
p = p->next;
}
}
void InputList(LinkList* L, int n)
{
LinkList p;
p = (*L)->next;
for (int i = 0; i < n; i++)
{
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
int main()
{
LinkList L;
int n;
scanf_s("%d", &n);
ElemType data[MaxSize];
for (int j = 0; j < n; j++)
{
scanf_s("%d", &data[j]);
}
CreateList(&L, n, data);
int i;
scanf_s("%d", &i);
if (i > n || i < 1)
printf("error!\n");
int m;
scanf_s("%d", &m);
InsertList(&L, i, n, m);
InputList(&L, n + 1);
return 0;
}
有大佬帮忙看看为什么这段代码在OJ上提交会显示Runtime error吗?