(求教)这要怎么改:数据结构单链表删除某一个值的代码
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
//定义结点
typedef struct node{
int data;
struct node* next;
}listnode,*linklist;
//定义创建链表的函数
void create(linklist head)
{int x;scanf("%d",&x);
while(x!=-1)
{listnode *p=(listnode *)malloc(sizeof(listnode));p->data =x;
p->next=head->next;head->next=p;
scanf("%d",&x);}
}
//定义删除结点值为value的函数
int Remove(linklist head,int value)
{ listnode*p;listnode*q;
p=head->next;q=head;
while(p!=NULL)
{if(p->data==value)
{q->next=p->next;p=q->next;}
else
{p=p->next;q=q->next;} }
}
//定义输出链表的函数
void print_linklist(linklist head)
{ //head=head->next;
if(head==NULL) return;
printf("%d",head->data);//(在这出的错)***
print_linklist(head->next);
}
int main()
{ int m;listnode *head=(listnode *)malloc(sizeof(listnode));create(head);
printf("删除前:\n");print_linklist(head);
system("pause");//系统暂停
//scanf("%d",&m);Remove(head,m);
//printf("\n删除后:\n");print_linklist(head);
//system("pause");//系统暂停
//free(head); //释放
}
下面是报错的内容,大概意思就是访问head时(代码31行)出错
实验1.exe 中的 0x009115bb 处最可能的异常: 0xC0000005: 读取位置 0xcdcdcdcd 时发生访问冲突
实验1.exe 中的 0x009115bb 处有未经处理的异常: 0xC0000005: 读取位置 0xcdcdcdcd 时发生访问冲突