c语言怎么声明多个链表,然后放在一个结构体中?
比如说第一个链表是学生的基本信息链表,第二个链表是学生的各科成绩,第三个链表是各科老师的信息,然后把三个链表放到一个结构体中,应该这么声明,在函数中如何调用?...
比如说第一个链表是学生的基本信息链表,第二个链表是学生的各科成绩,第三个链表是各科老师的信息,然后把三个链表放到一个结构体中,应该这么声明,在函数中如何调用?
展开
2个回答
展开全部
typedef struct student {
char name[128];
int age;
// ...
}student_t, *student_link;
struct score {
int math;
int physical;
//...
}score_t, *score_link;
struct teacher {
char name[128];
int teach_type;
//...
}teacher_t, *teacher_link;
typedef struct myclass {
student_link stu_link;
score_link score_info;
teacher_link teacher_info;
}myclass_t;
void create_student_info(student_link *s) {
student_link l = *s;
student_t *p = l;
// create your student info here.
}
int main()
{
myclass_t cls;
cls.stu_link = NULL;
cls.score_info = NULL;
cls.teacher_info = NULL;
create_student_info(&(cls.stu_link));
return 0;
}
char name[128];
int age;
// ...
}student_t, *student_link;
struct score {
int math;
int physical;
//...
}score_t, *score_link;
struct teacher {
char name[128];
int teach_type;
//...
}teacher_t, *teacher_link;
typedef struct myclass {
student_link stu_link;
score_link score_info;
teacher_link teacher_info;
}myclass_t;
void create_student_info(student_link *s) {
student_link l = *s;
student_t *p = l;
// create your student info here.
}
int main()
{
myclass_t cls;
cls.stu_link = NULL;
cls.score_info = NULL;
cls.teacher_info = NULL;
create_student_info(&(cls.stu_link));
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询