2020-10-03 20:50

# 引发了异常: 读取访问权限冲突。 L1 是 nullptr。//单链表练习

``````//编写程序将两个有序表LA,LB合并成一个有序表LC并且上机调试
#include<stdio.h>
#include<malloc.h>
typedef struct LNode
{
int data;
struct LNode *next;
void CreateList(LinkNode *&L, int a[], int n)//头插法创建单链表
{
L->next = NULL;//很重要，没有这个会有文件访问冲突的问题
if (n > 0)
{
for (int i = 0; i < n; i++)
{
s->data = a[i];
s->next = L->next;
L->next = s;
}
}
else
{
printf("error!n小于0无法顺利创建单链表");
}
}
void CreateListF(LinkNode *&L, int a[], int n)//尾插法
{
if (n > 0)
{
for (int i = 0; i < n; i++)
{
s->data = a[i];
r->next = s;
r = s;
}
r->next = NULL;
}
else
{
printf("error!!");
}
}
{
while (p != NULL)
{
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
{
if (L1 = NULL)
{
return L2;
}
else if(L2 = NULL)
{
return L1;
}
if (L1->data < L2->data)
{
L3 = L1;
L3->next = Merge(L1->next, L2);
}
else
{
L3 = L2;
L3->next = Merge(L1, L2->next);
}
return L3;
}
int main()
{
int a[10] = { 2,4,6,8,10 };
int b[10] = { 1,3,5,7,9 };
CreateList(L1, a, 5);
CreateList(L2, b, 5);
L3 = Merge(L1, L2);
dispList(L3);
}
``````
• 点赞
• 写回答
• 关注问题
• 收藏
• 邀请回答