//List.c
#include "List.h"
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
void CreateEmptyList(List *L)
{
*L=(Position)malloc(sizeof(struct Node)); //清空链表(只留头节点)
(*L)->Next_course=NULL;
(*L)->Next_name=NULL;
(*L)->Name_next=NULL;
(*L)->Name_num=NULL;
}
Position Find_same_course(ElementType *X,List L) //在链表中寻找课程相同课程名的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Next_course!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Next_course;
if(!strcmp(X,P->Course))
{
return P;
} //没问题
}
if(!strcmp(X,L->Course))
{
return L;
}
return P=NULL;
}
Position Find_same_name(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Next_name!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Next_name;
if(!strcmp(X,P->Name))
{
return P;
} //没问题
}
if(!strcmp(X,L->Name))
{
return L;
}
return P=NULL;
}
Position Find_same_name_num(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Name_num!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Name_num;
if(!strcmp(X,P->Name))
{
return P;
} //没问题
}
if(!strcmp(X,L->Name))
{
return L;
}
return P=NULL;
}
void InsertH_course(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Next_course;
L->Next_course=Jiedian;
Jiedian->Next_course=p;
}
void InsertH_name_num(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Name_num;
L->Name_num=Jiedian;
Jiedian->Name_num=p;
}
void InsertH_name(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Next_name;
L->Next_name=Jiedian;
Jiedian->Next_name=p;
}
void InsertH_name_next(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Name_next;
L->Name_next=Jiedian;
Jiedian->Name_next=p;
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//List.h
#ifndef _LIST_H_
typedef char ElementType;
#define LEN 15
struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
struct Node
{
ElementType Course[LEN];
ElementType Name[LEN];
Position Next_course;
Position Next_name;
Position Name_next;
Position Name_num;
};
void CreateEmptyList(List *L);
Position Find_same_course(ElementType *X,List L);
Position Find_same_name(ElementType *X,List L);
Position Find_same_name_num(ElementType *X,List L);
void InsertH_course(List L,Position Jiedian);
void InsertH_name_num(List L,Position Jiedian);
void InsertH_name(List L,Position Jiedian);
void InsertH_name_next(List L,Position Jiedian);
#endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//main.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include "List.h"
int main(void)
{
List School;
CreateEmptyList(&School); //生成了一个头节点,可用于之后的查找
printf("\nV1.0 By zhouxing-HIT-qq960020310%%%%%%%%%%%%%\n");
printf("\n%%%%%%%%%%%%%课程选课信息注册系统%%%%%%%%%%%%%\n");
int i;
while(1)
{
printf("\n*************请按照提示进行操作************\n");
printf("--1------进行选课情况导入!\n");
printf("--2------课程选课名单输出!\n");
printf("--3------学生所选课目录!\n");
printf("--4------退出课程管理系统!\n");
scanf("%d",&i);
switch(i)
{
case 1:
{
char p_course[LEN];
char q_name[LEN];
printf("**********请输入:课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
if(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
{
strcpy(School->Course,p_course);
strcpy(School->Name,q_name);
School->Next_course=School;
School->Next_name=School;
School->Name_next=School;
School->Name_num=School;
}
else
{
printf("----------感谢使用,再见!-----------");
return;
}
printf("**********请输入课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
while(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
{
Position TmpCell;
TmpCell=malloc(sizeof(struct Node));
strcpy(TmpCell->Course,p_course);
strcpy(TmpCell->Name,q_name);
TmpCell->Next_course=TmpCell; //生成一个结构体的所有指针成员都指向自己的节点
TmpCell->Next_name=TmpCell;
TmpCell->Name_next=TmpCell;
TmpCell->Name_num=TmpCell;
Position g,h,w,y;
g=Find_same_course(p_course,School);
h=Find_same_name_num(q_name,School);
if(g!=NULL)
{
w=Find_same_name(q_name,g);
if(w==NULL)
{
if(h==NULL)
{
InsertH_name(g,TmpCell);
InsertH_name_num(School,TmpCell);
}
else
{
InsertH_name(g,TmpCell);
InsertH_name_next(h,TmpCell);
}
}
else
{
printf("\n************输入重复啦!\n");
}
}
if(g==NULL)
{
if(h==NULL)
{
InsertH_course(School,TmpCell);
InsertH_name_num(School,TmpCell);
}
else
{
InsertH_course(School,TmpCell);
InsertH_name_next(h,TmpCell);
}
}
printf("**********请输入课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
if((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))
{
break;
}
}
break;
}
case 2:
{
printf("请输入您要查询的课程的名字:\n");
char s[LEN];
scanf("%s",s);
List y,y_1,y_2;
y=School;
y_1=NULL;
while(strcmp(s,"quit"))
{
while(y->Next_course!=School)
{
y=y->Next_course;
if(!strcmp(y->Course,s))
{
y_1=y;
}
}
if(!strcmp(School->Course,s))
{
y_1=School;
}
if(y_1==NULL)
{
printf("课程名输入错误,请重新输入:\n");
}
else
{
y_2=y_1;
while(y_2->Next_name!=y_1)
{
y_2=y_2->Next_name;
printf("%s\n",y_2->Name);
}
printf("%s\n",y_1->Name);
}
break;
}
break;
}
case 3:
{
printf("请输入您要查询的学生的名字:\n");
char s[LEN];
scanf("%s",s);
List y_3,y_1_1,y_2_1;
y_1_1=NULL;
y_3=School;
while(strcmp(s,"quit"))
{
while(y_3->Name_num!=School)
{
y_3=y_3->Name_num;
if(!strcmp(y_3->Name,s))
{
y_1_1=y_3;
}
}
if(!strcmp(School->Name,s))
{
y_1_1=School;
}
if(y_1_1==NULL)
{
printf("课程名输入错误,请重新输入:\n");
}
else
{
y_2_1=y_1_1;
while(y_2_1->Name_next!=y_1_1)
{
y_2_1=y_2_1->Name_next;
printf("%s\n",y_2_1->Course);
}
printf("%s\n",y_1_1->Course);
}
break;
}
break;
}
case 4:
{
printf("谢谢使用,再见!\n");
return;
}
}
}
}
//List.h
#ifndef _LIST_H_
typedef char ElementType;
#define LEN 15
struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
struct Node
{
ElementType Course[LEN];
ElementType Name[LEN];
Position Next_course;
Position Next_name;
Position Name_next;
Position Name_num;
};
void CreateEmptyList(List *L);
Position Find_same_course(ElementType *X,List L);
Position Find_same_name(ElementType *X,List L);
Position Find_same_name_num(ElementType *X,List L);
void InsertH_course(List L,Position Jiedian);
void InsertH_name_num(List L,Position Jiedian);
void InsertH_name(List L,Position Jiedian);
void InsertH_name_next(List L,Position Jiedian);
#endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//List.c
#include "List.h"
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
void CreateEmptyList(List *L)
{
*L=(Position)malloc(sizeof(struct Node)); //清空链表(只留头节点)
(*L)->Next_course=NULL;
(*L)->Next_name=NULL;
(*L)->Name_next=NULL;
(*L)->Name_num=NULL;
}
Position Find_same_course(ElementType *X,List L) //在链表中寻找课程相同课程名的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Next_course!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Next_course;
if(!strcmp(X,P->Course))
{
return P;
} //没问题
}
if(!strcmp(X,L->Course))
{
return L;
}
return P=NULL;
}
Position Find_same_name(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Next_name!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Next_name;
if(!strcmp(X,P->Name))
{
return P;
} //没问题
}
if(!strcmp(X,L->Name))
{
return L;
}
return P=NULL;
}
Position Find_same_name_num(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Name_num!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Name_num;
if(!strcmp(X,P->Name))
{
return P;
} //没问题
}
if(!strcmp(X,L->Name))
{
return L;
}
return P=NULL;
}
void InsertH_course(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Next_course;
L->Next_course=Jiedian;
Jiedian->Next_course=p;
}
void InsertH_name_num(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Name_num;
L->Name_num=Jiedian;
Jiedian->Name_num=p;
}
void InsertH_name(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Next_name;
L->Next_name=Jiedian;
Jiedian->Next_name=p;
}
void InsertH_name_next(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Name_next;
L->Name_next=Jiedian;
Jiedian->Name_next=p;
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//main.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include "List.h"
int main(void)
{
List School;
CreateEmptyList(&School); //生成了一个头节点,可用于之后的查找
printf("\nV1.0 By zhouxing-HIT-qq960020310%%%%%%%%%%%%%\n");
printf("\n%%%%%%%%%%%%%课程选课信息注册系统%%%%%%%%%%%%%\n");
int i;
while(1)
{
printf("\n*************请按照提示进行操作************\n");
printf("--1------进行选课情况导入!\n");
printf("--2------课程选课名单输出!\n");
printf("--3------学生所选课目录!\n");
printf("--4------退出课程管理系统!\n");
scanf("%d",&i);
switch(i)
{
case 1:
{
char p_course[LEN];
char q_name[LEN];
printf("**********请输入:课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
if(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
{
strcpy(School->Course,p_course);
strcpy(School->Name,q_name);
School->Next_course=School;
School->Next_name=School;
School->Name_next=School;
School->Name_num=School;
}
else
{
printf("----------感谢使用,再见!-----------");
return;
}
printf("**********请输入课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
while(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
{
Position TmpCell;
TmpCell=malloc(sizeof(struct Node));
strcpy(TmpCell->Course,p_course);
strcpy(TmpCell->Name,q_name);
TmpCell->Next_course=TmpCell; //生成一个结构体的所有指针成员都指向自己的节点
TmpCell->Next_name=TmpCell;
TmpCell->Name_next=TmpCell;
TmpCell->Name_num=TmpCell;
Position g,h,w,y;
g=Find_same_course(p_course,School);
h=Find_same_name_num(q_name,School);
if(g!=NULL)
{
w=Find_same_name(q_name,g);
if(w==NULL)
{
if(h==NULL)
{
InsertH_name(g,TmpCell);
InsertH_name_num(School,TmpCell);
}
else
{
InsertH_name(g,TmpCell);
InsertH_name_next(h,TmpCell);
}
}
else
{
printf("\n************输入重复啦!\n");
}
}
if(g==NULL)
{
if(h==NULL)
{
InsertH_course(School,TmpCell);
InsertH_name_num(School,TmpCell);
}
else
{
InsertH_course(School,TmpCell);
InsertH_name_next(h,TmpCell);
}
}
printf("**********请输入课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
if((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))
{
break;
}
}
break;
}
case 2:
{
printf("请输入您要查询的课程的名字:\n");
char s[LEN];
scanf("%s",s);
List y,y_1,y_2;
y=School;
y_1=NULL;
while(strcmp(s,"quit"))
{
while(y->Next_course!=School)
{
y=y->Next_course;
if(!strcmp(y->Course,s))
{
y_1=y;
}
}
if(!strcmp(School->Course,s))
{
y_1=School;
}
if(y_1==NULL)
{
printf("课程名输入错误,请重新输入:\n");
}
else
{
y_2=y_1;
while(y_2->Next_name!=y_1)
{
y_2=y_2->Next_name;
printf("%s\n",y_2->Name);
}
printf("%s\n",y_1->Name);
}
break;
}
break;
}
case 3:
{
printf("请输入您要查询的学生的名字:\n");
char s[LEN];
scanf("%s",s);
List y_3,y_1_1,y_2_1;
y_1_1=NULL;
y_3=School;
while(strcmp(s,"quit"))
{
while(y_3->Name_num!=School)
{
y_3=y_3->Name_num;
if(!strcmp(y_3->Name,s))
{
y_1_1=y_3;
}
}
if(!strcmp(School->Name,s))
{
y_1_1=School;
}
if(y_1_1==NULL)
{
printf("课程名输入错误,请重新输入:\n");
}
else
{
y_2_1=y_1_1;
while(y_2_1->Name_next!=y_1_1)
{
y_2_1=y_2_1->Name_next;
printf("%s\n",y_2_1->Course);
}
printf("%s\n",y_1_1->Course);
}
break;
}
break;
}
case 4:
{
printf("谢谢使用,再见!\n");
return;
}
}
}
}
//main.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include "List.h"
int main(void)
{
List School;
CreateEmptyList(&School); //生成了一个头节点,可用于之后的查找
printf("\nV1.0 By zhouxing-HIT-qq960020310%%%%%%%%%%%%%\n");
printf("\n%%%%%%%%%%%%%课程选课信息注册系统%%%%%%%%%%%%%\n");
int i;
while(1)
{
printf("\n*************请按照提示进行操作************\n");
printf("--1------进行选课情况导入!\n");
printf("--2------课程选课名单输出!\n");
printf("--3------学生所选课目录!\n");
printf("--4------退出课程管理系统!\n");
scanf("%d",&i);
switch(i)
{
case 1:
{
char p_course[LEN];
char q_name[LEN];
printf("**********请输入:课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
if(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
{
strcpy(School->Course,p_course);
strcpy(School->Name,q_name);
School->Next_course=School;
School->Next_name=School;
School->Name_next=School;
School->Name_num=School;
}
else
{
printf("----------感谢使用,再见!-----------");
return;
}
printf("**********请输入课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
while(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
{
Position TmpCell;
TmpCell=malloc(sizeof(struct Node));
strcpy(TmpCell->Course,p_course);
strcpy(TmpCell->Name,q_name);
TmpCell->Next_course=TmpCell; //生成一个结构体的所有指针成员都指向自己的节点
TmpCell->Next_name=TmpCell;
TmpCell->Name_next=TmpCell;
TmpCell->Name_num=TmpCell;
Position g,h,w,y;
g=Find_same_course(p_course,School);
h=Find_same_name_num(q_name,School);
if(g!=NULL)
{
w=Find_same_name(q_name,g);
if(w==NULL)
{
if(h==NULL)
{
InsertH_name(g,TmpCell);
InsertH_name_num(School,TmpCell);
}
else
{
InsertH_name(g,TmpCell);
InsertH_name_next(h,TmpCell);
}
}
else
{
printf("\n************输入重复啦!\n");
}
}
if(g==NULL)
{
if(h==NULL)
{
InsertH_course(School,TmpCell);
InsertH_name_num(School,TmpCell);
}
else
{
InsertH_course(School,TmpCell);
InsertH_name_next(h,TmpCell);
}
}
printf("**********请输入课程名+学生名(空格隔开)************\n");
scanf("%s",p_course);
scanf("%s",q_name);
if((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))
{
break;
}
}
break;
}
case 2:
{
printf("请输入您要查询的课程的名字:\n");
char s[LEN];
scanf("%s",s);
List y,y_1,y_2;
y=School;
y_1=NULL;
while(strcmp(s,"quit"))
{
while(y->Next_course!=School)
{
y=y->Next_course;
if(!strcmp(y->Course,s))
{
y_1=y;
}
}
if(!strcmp(School->Course,s))
{
y_1=School;
}
if(y_1==NULL)
{
printf("课程名输入错误,请重新输入:\n");
}
else
{
y_2=y_1;
while(y_2->Next_name!=y_1)
{
y_2=y_2->Next_name;
printf("%s\n",y_2->Name);
}
printf("%s\n",y_1->Name);
}
break;
}
break;
}
case 3:
{
printf("请输入您要查询的学生的名字:\n");
char s[LEN];
scanf("%s",s);
List y_3,y_1_1,y_2_1;
y_1_1=NULL;
y_3=School;
while(strcmp(s,"quit"))
{
while(y_3->Name_num!=School)
{
y_3=y_3->Name_num;
if(!strcmp(y_3->Name,s))
{
y_1_1=y_3;
}
}
if(!strcmp(School->Name,s))
{
y_1_1=School;
}
if(y_1_1==NULL)
{
printf("课程名输入错误,请重新输入:\n");
}
else
{
y_2_1=y_1_1;
while(y_2_1->Name_next!=y_1_1)
{
y_2_1=y_2_1->Name_next;
printf("%s\n",y_2_1->Course);
}
printf("%s\n",y_1_1->Course);
}
break;
}
break;
}
case 4:
{
printf("谢谢使用,再见!\n");
return;
}
}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//List.h
#ifndef _LIST_H_
typedef char ElementType;
#define LEN 15
struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
struct Node
{
ElementType Course[LEN];
ElementType Name[LEN];
Position Next_course;
Position Next_name;
Position Name_next;
Position Name_num;
};
void CreateEmptyList(List *L);
Position Find_same_course(ElementType *X,List L);
Position Find_same_name(ElementType *X,List L);
Position Find_same_name_num(ElementType *X,List L);
void InsertH_course(List L,Position Jiedian);
void InsertH_name_num(List L,Position Jiedian);
void InsertH_name(List L,Position Jiedian);
void InsertH_name_next(List L,Position Jiedian);
#endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//List.c
#include "List.h"
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
void CreateEmptyList(List *L)
{
*L=(Position)malloc(sizeof(struct Node)); //清空链表(只留头节点)
(*L)->Next_course=NULL;
(*L)->Next_name=NULL;
(*L)->Name_next=NULL;
(*L)->Name_num=NULL;
}
Position Find_same_course(ElementType *X,List L) //在链表中寻找课程相同课程名的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Next_course!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Next_course;
if(!strcmp(X,P->Course))
{
return P;
} //没问题
}
if(!strcmp(X,L->Course))
{
return L;
}
return P=NULL;
}
Position Find_same_name(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Next_name!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Next_name;
if(!strcmp(X,P->Name))
{
return P;
} //没问题
}
if(!strcmp(X,L->Name))
{
return L;
}
return P=NULL;
}
Position Find_same_name_num(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点
{
Position P;
P=L; //寻找某个元素在链表中的地址
while(P->Name_num!=L) //若找到,返回元素所在的节点指针,否则返回空指针
{
P=P->Name_num;
if(!strcmp(X,P->Name))
{
return P;
} //没问题
}
if(!strcmp(X,L->Name))
{
return L;
}
return P=NULL;
}
void InsertH_course(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Next_course;
L->Next_course=Jiedian;
Jiedian->Next_course=p;
}
void InsertH_name_num(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Name_num;
L->Name_num=Jiedian;
Jiedian->Name_num=p;
}
void InsertH_name(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Next_name;
L->Next_name=Jiedian;
Jiedian->Next_name=p;
}
void InsertH_name_next(List L,Position Jiedian)
{
if(L==NULL)
{
return;
}
List p; //后插,直接插入节点
p=L->Name_next;
L->Name_next=Jiedian;
Jiedian->Name_next=p;
}