正弦定理 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 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示