简体   繁体   English

我的时间表表程序中的任何建议

[英]any proposal in my time schedule table program

I create a struct to hold the class schedule table: 我创建一个结构来保存课程表:

struct timetable_t {
    int id;
    int weekday;
    float start_time;
    float end_time;
    int start_week;
    int end_week;
    int is_even;
    char* name;
    char* location;
};

typedef struct t_class {
    struct timetable_t t;
    struct t_class* pre;
    struct t_class* next;
}CLASS;

below is the data: 以下是数据:

static struct timetable_t timetable[] = {
    {113172, 1, 10.10, 12.00, 3, 17, 2, "PE", "B-410"},
    {121172, 1, 14.00, 15.50, 1, 17, 2, "English", "B-101"},
    {131172, 1, 16.00, 18.00, 1, 17, 2, "Music", "B-101"},
    {141132, 1, 18.30, 20.30, 2, 13, 2, "Science", "C2-207"},
};

create double link list 创建双链接列表

CLASS* create_class(struct timetable_t* arr, int len) {
    int i;
    CLASS* head = NEW(1);
    CLASS* p = head;
    CLASS* t = NULL;
    for (i = 0; i < len; ++i) {
        t = NEW(1);
        t->t.id = arr[i].id;
        t->t.weekday = arr[i].weekday;
        t->t.start_time = arr[i].start_time;
        t->t.end_time= arr[i].end_time;
        t->t.start_week = arr[i].start_week;
        t->t.end_week = arr[i].end_week;
        t->t.is_even = arr[i].is_even;
        t->t.name = arr[i].name;
        t->t.location = arr[i].location;
        t->pre = p;
        p->next = t;
        p = p->next;
    }
    head->pre = p;
    p->next = head;
    return head;
}

Now I use a linklist double linked list to organize the data, in my program, by compare the current "hour.day" if I want to get the current class. 现在,在我的程序中,如果要获取当前的类,可以通过比较当前的“ hour.day”来使用链接列表双链表来组织数据。 then problems comes, is there any simple way to get the next class if current class is NULL. 然后问题来了,如果当前类为NULL,是否有任何简单的方法来获取下一个类。

The way I have done this is make head a global. 我做到这一点的方法是使人走向全球。 And then provide a function that walks the list (starting at head) to get what you want. 然后提供一个遍历列表(从头开始)以获取所需内容的功能。 So you can count, get_next, get_next_by_value things like that. 这样您就可以计算出诸如此类的get_next,get_next_by_value值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM