m0_73955858 2022-11-17 13:25 采纳率: 0%
浏览 24

能帮我看看我这个删除链表错在哪了吗

#include<stdio.h>
#include<stdlib.h>
struct stu{
int num;
int scores;
struct stunext;};
struct stu
kiang(){
struct stu*head,*tail,p;
int num;
head=tail=NULL;
scanf("%d",&num);
while(num){
p=(struct stu
)malloc(sizeof(struct stu));
scanf("%d",&p->num);
scanf("%d",&p->scores);
p->next=NULL;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
num--;}
return head;}
int main(){
struct stu *head,*o,*p1,*p2;
int n;
scanf("%d",&n);
head=kiang();
p1=head;
p2=head->next;
if(head->num==n)
{o=head;
head=head->next;
}
while(p2!=NULL)
if(p2->num==n)
{p1->next=p2->next;
break;}
else
{p1=p2;
p2=p2->next;}
while(head!=NULL)
{printf("%d %d\n",head->num,head->scores);
head=head->next;}
return 0;}

  • 写回答

3条回答 默认 最新

  • hello_world&& 2022-11-17 13:48
    关注

    这三处均是指针,分别改为
    struct stu *next;
    *p;
    p=(struct stu *)malloc

    img

    评论 编辑记录

报告相同问题?

问题事件

  • 修改了问题 11月17日
  • 修改了问题 11月17日
  • 创建了问题 11月17日

悬赏问题

  • ¥15 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同
  • ¥15 excel 上下按钮 显示行
  • ¥20 云卓h12pro 数传问题