m0_61800796 2021-10-13 14:05 采纳率: 93.9%
浏览 39
已结题

c语言链表问题(问了两天了还没搞明白)

img

img

img


有大佬能帮我看看哪里不对吗,真的改了6,7次了,次次都不对

  • 写回答

5条回答 默认 最新

  • qfl_sdu 2021-10-13 14:39
    关注

    代码修改如下:

    #include <stdio.h>
    #include <stdlib.h>
    struct student
    {
        int score;
        struct student* next;
    };
    
    struct student* create()
    {
        int i = 2;
        struct student* head,*middle,*end;
        head = (struct student*)malloc(sizeof(struct student));
        end = (struct student*)malloc(sizeof(struct student));
        head->next = NULL;
        end->next = NULL;
        middle = head;
        printf("请输入第1个学生的分数:");
        scanf("%d",&end->score);
        while (end->score != -1)
        {
            middle->next = end;
            middle = end;
            end = (struct student*)malloc(sizeof(struct student));
            end->next = NULL;
            printf("请输入第%d个学生的分数:",i);
            scanf("%d",&end->score);
            i++;
        } 
        middle->next = end;
        return head;
    }
    
    void print(struct student* a)
    {
        struct student *p;
        p=a->next;
        while(p && p->score != -1)
        {
            printf("%d ",p->score);
            p = p->next;
        }
    }
    
    int main()
    {
        struct student* head = create();
        print(head);
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 10月21日
  • 已采纳回答 10月13日
  • 创建了问题 10月13日

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?