struct node
{int data;
struct node *next;
};
struct node *create()
{
struct node *p;
p=(struct node *)malloc(sizeof(struct node));
p->next=0;
return p;
}
main()
{
struct node *head,*q,*p,*t;
int i;
int x;
head=create();
for(i=1;i<=10;i++)
{
printf("please input data:");
scanf("%d",&x);
q=create();
q->data=x;
if(i==1)
{
head->next=q;
p=q;
}
else
{p->next=q;
p=q;}
}
}
c语言 定义一个函数用来删除指定的链表结点,然后调用。
答案:2 悬赏:80
解决时间 2021-03-05 22:45
- 提问者网友:绿海猖狂
- 2021-03-05 08:25
最佳答案
- 二级知识专家网友:不服输的倔强
- 2021-03-05 08:55
Status ListDelete(struct node *L, int i, int *e)
{
int j;
struct node *p, *q;
p = L;
j = 1;
while (p->next && j < i)
{
p = p->next;
++j;
}
if (!(p->next) || j > i)
return ERROR;
q = p->next;
p->next = q->next;
*e = q->data;
free(q);
return OK;
}
全部回答
- 1楼网友:开心就好
- 2021-03-05 09:22
感觉你的链表写的很怪,,,,,链表的结点需要随机分配内存空间,但你没分配。。。。而且你链表头结点里的下个地址是0,然而你给后面几个结点里面的下个地址还是0.。。。。。感觉就在一个结点里面绕一样。。。。。所以你先网上看下具体的链表该怎么写。。。。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |