我创建了一个结构来保存类调度表:
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;
以下是数据:
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"},
};
创建双链接列表
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;
}
现在我使用linklist双链表来组织我的程序中的数据,比较当前的“hour.day”,如果我想获得当前的类。然后出现问题,如果当前的类为NULL,是否有任何简单的方法来获取下一个类。
答案 0 :(得分:0)
我这样做的方法是让头脑变得全球化。然后提供一个遍历列表的功能(从头开始)以获得您想要的功能。所以你可以计算,get_next,get_next_by_value这样的事情。