不会写这道循环队列的

 高校实验任务安排程序设计与实现问题描述

学生选课问题中的数据元素具有如下形式:学生的自然情况包括姓名、学号、班级。2.功能要求要求完成以下功能:

⑴ 插入:将预约做实验的学生插入到合适的时间队列中;

⑵ 删除:时间队列中前5位学生可以在该时间做实验;

⑶ 查询:教师可以随时查询某个时间队列中学生的预约情况;

⑷ 修改:在没做实验之前,学生可以对预约的时间进行修改;

⑸ 输出:输出每个时间队列中预约的学生名单。

 

根据个人理解:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct student {
    char name[20];
    int id;
    char clazz[10];
    struct student *next;
};

struct student *head[5];

void insert(struct student *stu, int time) {
    struct student *p = head[time];
    if (p == NULL || strcmp(stu->clazz, p->clazz) < 0) {
        stu->next = head[time];
        head[time] = stu;
    } else {
        while (p->next != NULL && strcmp(stu->clazz, p->next->clazz) > 0) {
            p = p->next;
        }
        stu->next = p->next;
        p->next = stu;
    }
}

void delete(int time) {
    for (int i = 0; i < 5 && head[time] != NULL; i++) {
        struct student *p = head[time];
        head[time] = head[time]->next;
        free(p);
    }
}

void query(int time) {
    printf("Time %d: ", time);
    struct student *p = head[time];
    while (p != NULL) {
        printf("%s(%d, %s) ", p->name, p->id, p->clazz);
        p = p->next;
    }
    printf("\n");
}

void modify(int id, int time) {
    for (int i = 0; i < 5; i++) {
        struct student *p = head[i];
        while (p != NULL) {
            if (p->id == id) {
                struct student *q = p;
                p = p->next;
                q->next = NULL;
                insert(q, time);
                return;
            }
            p = p->next;
        }
    }
}

void output() {
    for (int i = 0; i < 5; i++) {
        query(i);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int time, choice;
        struct student *stu = (struct student *)malloc(sizeof(struct student));
        scanf("%s%d%s", stu->name, &stu->id, stu->clazz);
        scanf("%d", &choice);
        if (choice == 1) {
            scanf("%d", &time);
            insert(stu, time);
        } else if (choice == 2) {
            scanf("%d", &time);
            modify(stu->id, time);
        } else if (choice == 3) {
            output();
        } else {
            delete(i);
        }
    }
    return 0;
}