求帮忙改程序
题目如下
对给定的单链表 L ,设计一个算法,删除 L 中值为 x 的结点的直接前驱结点。
测试输入 期待的输出 时间限制 内存限制 额外进程
测试用例 1
11 22 33 44 55 66 77↵
44↵
11 22 44 55 66 77↵
1秒 64M 0
测试用例 2
23 45 11 45 67 88 4 33 78↵
88↵
23 45 11 45 88 4 33 78↵
1秒 64M 0
测试用例 3
12 23 34 45 56 67 78 89↵
12↵
该结点没有前驱结点↵
1秒 64M 0
我的程序
我的问题
RE: 无效内存引用
#include<stdio.h>
#include<stdlib.h>
struct Lnode
{
int data;
Lnode *next;
}Lnode;
int main(){
int a[10],cou1,cou2;
for(int i=0,cou1=0;a[i]!='\n';i++){
scanf("%d",&a[i]);
cou1++;
}
int m;
scanf("%d",&m);
for(int i=0;a[i]!='\n';i++){
printf("%d\n",a[i]);
}
struct Lnode *head;
struct Lnode *p;
p=(struct Lnode*)malloc(sizeof(struct Lnode));
p->next=NULL;
head=p;
if(p->data==a[0]) printf("该结点没有前驱结点\n");
else{
for(int n=1,cou2=0;p->data!=m;n++)
{
cou2++;
if(p->next=NULL) return 1;
else p++;
}
struct Lnode *q;
q=(struct Lnode*)malloc(sizeof(struct Lnode));
q->next=NULL;
head=q;
for(int j=0;q<p;j++)
{
printf("%d",a[j]);
}
for(int k=cou2+1;k<=cou1;k++)
{
printf("%d",a[k]);
}
printf("\n");
return 0;
}
}