From e3d2b6d658789391999df196a62f8bd44a5a3bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B1=E8=97=8Fblue?= <16531833+zhangxinru2333@user.noreply.gitee.com> Date: Sat, 3 Jan 2026 10:25:53 +0000 Subject: [PATCH] update linklist_op. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 深藏blue <16531833+zhangxinru2333@user.noreply.gitee.com> --- linklist_op | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/linklist_op b/linklist_op index e69de29..ca50e37 100644 --- a/linklist_op +++ b/linklist_op @@ -0,0 +1,107 @@ +#include "score_struct.h" + +// ===================== 初始化单链表函数 ===================== +void InitLinkList(void **list, int type) { + if (type == 1) { // 初始化角色链表 + RoleLinkList *roleList = (RoleLinkList *)list; + *roleList = (RoleLinkList)malloc(sizeof(RoleNode)); + if (*roleList == NULL) { + printf("内存分配失败!\n"); + exit(1); + } + (*roleList)->next = NULL; + memset((*roleList)->roleName, 0, sizeof((*roleList)->roleName)); + memset((*roleList)->roleDesc, 0, sizeof((*roleList)->roleDesc)); + (*roleList)->perm = PERM_NONE; + } else if (type == 2) { // 初始化用户链表 + UserLinkList *userList = (UserLinkList *)list; + *userList = (UserLinkList)malloc(sizeof(UserNode)); + if (*userList == NULL) { + printf("内存分配失败!\n"); + exit(1); + } + (*userList)->next = NULL; + memset((*userList)->username, 0, sizeof((*userList)->username)); + memset((*userList)->password, 0, sizeof((*userList)->password)); + memset((*userList)->roleName, 0, sizeof((*userList)->roleName)); + } else if (type == 3) { // 初始化成绩链表(适配学分+成绩类型) + ScoreLinkList *scoreList = (ScoreLinkList *)list; + *scoreList = (ScoreLinkList)malloc(sizeof(ScoreNode)); + if (*scoreList == NULL) { + printf("内存分配失败!\n"); + exit(1); + } + (*scoreList)->next = NULL; + memset((*scoreList)->studentID, 0, sizeof((*scoreList)->studentID)); + memset((*scoreList)->courseID, 0, sizeof((*scoreList)->courseID)); + memset((*scoreList)->courseName, 0, sizeof((*scoreList)->courseName)); + (*scoreList)->score = 0.0; + (*scoreList)->scoreType = SCORE_TYPE_PERCENT; + (*scoreList)->credit = 0.0; + memset((*scoreList)->semester, 0, sizeof((*scoreList)->semester)); + memset((*scoreList)->className, 0, sizeof((*scoreList)->className)); + } + printf("链表初始化成功!\n"); +} + +// ===================== 显示单链表内容函数 ===================== +void dispLinkList(void *list, int type) { + if (type == 1) { // 显示角色链表 + RoleLinkList roleList = (RoleLinkList)list; + RoleNode *p = roleList->next; + if (p == NULL) { + printf("角色链表为空!\n"); + return; + } + printf("===== 角色列表 =====\n"); + printf("角色名\t\t描述\t\t权限\n"); + while (p != NULL) { + printf("%s\t\t%s\t\t%d\n", p->roleName, p->roleDesc, p->perm); + p = p->next; + } + } else if (type == 2) { // 显示用户链表 + UserLinkList userList = (UserLinkList)list; + UserNode *p = userList->next; + if (p == NULL) { + printf("用户链表为空!\n"); + return; + } + printf("===== 用户列表 =====\n"); + printf("账号(姓名)\t角色\t\t核心信息\n"); + while (p != NULL) { + printf("%s\t\t%s\t\t", p->username, p->roleName); + if (strcmp(p->roleName, "管理者") == 0) { + printf("管理部门:%s\n", p->info.admin.adminDept); + } else if (strcmp(p->roleName, "老师") == 0) { + printf("工号:%s 所教课程:%s\n", p->info.teacher.teacherID, p->info.teacher.teachCourse); + } else if (strcmp(p->roleName, "学生") == 0) { + printf("学号:%s 专业:%s GPA:%.2f\n", p->info.student.studentID, p->info.student.major, p->info.student.gpa); + } + p = p->next; + } + } else if (type == 3) { // 显示成绩链表(适配学分+成绩类型) + ScoreLinkList scoreList = (ScoreLinkList)list; + ScoreNode *p = scoreList->next; + if (p == NULL) { + printf("成绩链表为空!\n"); + return; + } + printf("===== 成绩列表 =====\n"); + printf("学号\t\t课程ID\t\t课程名\t\t成绩\t\t类型\t\t学分\t\t学期\t\t班级\n"); + while (p != NULL) { + char typeStr[10]; + switch (p->scoreType) { + case SCORE_TYPE_PERCENT: strcpy(typeStr, "百分制"); break; + case SCORE_TYPE_FIVE: strcpy(typeStr, "五级制"); break; + case SCORE_TYPE_TWO: strcpy(typeStr, "两级制"); break; + default: strcpy(typeStr, "未知"); + } + printf("%s\t\t%s\t\t%s\t\t%.1f\t\t%s\t\t%.1f\t\t%s\t\t%s\n", + p->studentID, p->courseID, p->courseName, + p->score, typeStr, p->credit, p->semester, p->className); + p = p->next; + } + } + printf("====================\n"); +} + -- Gitee