(求教)这要怎么改:数据结构单链表删除某一个值的代码

(求教)这要怎么改:数据结构单链表删除某一个值的代码

#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 时发生访问冲突

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值