一、尾插法创建动态链表
二、(1)学生链表;(2)班级链表
1.1学生结构体
struct Student
{
int Chinese_score;
int Math_score;
int English_score;
int total_three_score;
float ave_three_score;
char *name;
struct Student *next;
};
1.2尾插法创建学生动态链表
struct Student *insertStudentBehindHead(struct Student *head, struct Student *new)
{
struct Student *p = head;
if (p == NULL){
head = new;
return head;
}
while(p->next != NULL){
p = p->next;
}
p->next = new;
return head;
}
struct Student *createStudentLinkBehindHead(struct Class *head1, struct Student *head2)
{
struct Student *new = NULL;
int j;
for(j = 0; j < head1->num_stu; j++){
new = (struct Student *)malloc(sizeof(struct Student));
new->name = (char *)malloc(128);
getchar();
printf("请输入第%d个学生姓名:\n", (j+1));
scanf("%s", new->name);
printf("请输入语文成绩:\n");
scanf("%d", &(new->Chinese_score));
printf("请输入数学成绩:\n");
scanf("%d", &(new->Math_score));
printf("请输入英语成绩:\n");
scanf("%d", &(new->English_score));
new->total_three_score = new->Chinese_score + new->Math_score + new->English_score;
new->ave_three_score = (float)new->total_three_score/3;
head2 = insertStudentBehindHead(head2, new);
}
return head2;
}
2.1班级结构体
struct Class
{
int num_stu;
int grade;
int total_Chinese;
int total_Math;
int total_English;
float ave_Chinese;
float ave_Math;
float ave_English;
struct Student *stu_score;
struct Student *stu_MaxTotalScore;
struct Student *stu_MinTotalScore;
struct Class *next;
};
2.2尾插法创建班级链表
struct Class *insertClassBehindHead(struct Class *head, struct Class *new)
{
struct Class *p = head;
if (p == NULL){
head = new;
return head;
}
while(p->next != NULL){
p = p->next;
}
p->next = new;
return head;
}
struct Class *createClassLinkBehindHead(struct Class *head1, struct Student *head2)
{
struct Class *new1 = NULL;
struct Student *pnew = NULL;
struct Student *pnew1 = NULL