C语言用链表常出错误,链表代码为什么会出现这么多一样的错误

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include

typedef struct data

{

int num;

struct data*next;

}data,*DATA;

DATA createlist();

void abclist(DATA);

void shanchu(DATA ,int );

void main()

{

int a;

DATA head=NULL;

head=createlist();

printf ("这是你输入的数据:");

abclist(head);

printf ("\n请输入你要删除的节点:");

scanf ("%d",&a);

printf ("这是删除操作后的链表:");

shanchu(head,a);

abclist(head);

}

DATA createlist()

{

printf ("请输入一组数据:");

DATA head=(DATA)malloc(sizeof(data));

DATA p;

int a;

p->num=a;

p->next=head->next;

head->next=NULL;

scanf ("%d",&a);

while (a!=0)

{

p=(DATA)malloc(sizeof(data));

p->num=a;

p->next=head->next;

head->next=p;

scanf ("%d",&a);

}

return head;

}

void abclist(DATA head)

{

DATA q=head->next;

while(q)

{

printf("%d ",q->num);

q=q->next;

}

}

void shanchu(DATA head,int a)

{

DATA p=head;

DATA q;

while (p->num!=NULL&&p->num!=a)

{

q=p;

p=p->next;

}

if (p!=NULL)

{

if (q==NULL)

head=p->next;

else

q->next=p->next;

}

return head;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值