正弦定理 2020-06-23 22:38 采纳率: 0%
浏览 288

如何解决双链表实现简单的学生管理系统?

为什么可以建立一个班级一名学生或者多个班级,但是建立一个班级里头多名学生就运行卡死,求大佬解释,解决下问题,拜托拜托拜托

目的:
一个年级,相当链表A,
该年级5个班,每个班5个人,相当于链表B1--B5。
做一个学生成绩管理系统


//学生成绩 
struct B{

    int chinese;
    int math;
    int english;
    int sum;
    int StudentID;  

    struct B *next;

};



//班级 
struct A{

    int ClassroomID;

    struct B *BHead;

    struct A *next;
};

//学生成绩链表 
struct B *B_studentlink(struct B *head,int number)
{
    struct B *p = head;
    struct B *new;
    int i;

    for(i=1 ; i<=number; i++)
    {
        new = (struct B*)malloc(sizeof(struct B));
        new->StudentID = i;


        if( p == NULL)
        {
            p = new;
            head = p;
        }
        else{
            while(p->next != NULL)
            {
                p = p->next;
            }

            p->next = new;
        }

    }

    return head;
}

//班级链表 
struct A *A_classlink(struct A *head,int classnumber,int classStudentNumber)
{
    struct A *p = head;
    struct B *student;
    struct A *new;
    int j;

    for(j=1; j<=classStudentNumber; j++)
    {
        student = NULL;

        new = (struct A*)malloc(sizeof(struct A));
        new->ClassroomID = j;

        student = B_studentlink(student,classStudentNumber);
        new->BHead = student;

        if(p ==NULL)
        {
            p = new;
            head = p;
        }
        else{
            while(p->next != NULL)
            {
                p = p->next;
            }

            p->next = new;
        }


    }

    return head;

}

//输入数据
struct A *InputData(struct A *Classhead)
{
struct A *p = Classhead;

struct B *q = NULL;

Classhead = p;


while(p != NULL)
{
    q = p->BHead;
    p->BHead = q;



    while(q != NULL)
    {
        printf("Please Scanf %d Ceng the %d student\n",p->ClassroomID,q->StudentID);

        printf("The chinese is\n");
        scanf("%d",&(q->chinese) );

        printf("The math is\n");
        scanf("%d",&(q->math) );

        printf("The english is\n");
        scanf("%d",&(q->english) );

        putchar('\n');
        q->sum =  (q->chinese)+(q->math)+(q->english);

        printf("#######################################\n");

        q= q->next;
    }

    p = p->next;
}

return Classhead;

}

``

``
int main()
{
int B_number;
int A_number;

struct A *Classhead = NULL;


printf("Please scanf how much Ceng\n");
scanf("%d",&A_number);  

printf("Please scanf how much student\n");
scanf("%d",&B_number);
putchar('\n');

Classhead = A_classlink(Classhead,A_number,B_number);//建立链表 

Classhead = InputData(Classhead);//输入数据 

return 0;

}

  • 写回答

1条回答 默认 最新

  • qiu_shaofeng 2020-06-24 10:39
    关注

    程序有时候能正常运行,有时候不能。在创建链表可以做点修改
    for(i=1 ; i<=number; i++)
    {
    new = (struct B*)malloc(sizeof(struct B));
    if(new==NULL) return -1;//可以添加
    new->StudentID = i;
    new->next=NULL; //当前节点的下一个为空

    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的